]> wimlib.net Git - wimlib/commitdiff
Avoid passing NULL as memcpy source (undefined behavior)
authorEric Biggers <ebiggers3@gmail.com>
Thu, 5 Nov 2015 02:43:27 +0000 (20:43 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 7 Nov 2015 21:05:15 +0000 (15:05 -0600)
src/dentry.c
src/unix_apply.c
src/win32_apply.c

index ff1a21420f0c2c068d422c1b9645368e96133675..caa3a51b4b86fb0d98e84f103781cc0274499294 100644 (file)
@@ -504,7 +504,8 @@ calculate_dentry_full_path(struct wim_dentry *dentry)
        d = dentry;
        do {
                p -= d->d_name_nbytes / sizeof(utf16lechar);
        d = dentry;
        do {
                p -= d->d_name_nbytes / sizeof(utf16lechar);
-               memcpy(p, d->d_name, d->d_name_nbytes);
+               if (d->d_name_nbytes)
+                       memcpy(p, d->d_name, d->d_name_nbytes);
                *--p = cpu_to_le16(WIM_PATH_SEPARATOR);
                d = d->d_parent;  /* assumes d == d->d_parent for root  */
        } while (!dentry_is_root(d));
                *--p = cpu_to_le16(WIM_PATH_SEPARATOR);
                d = d->d_parent;  /* assumes d == d->d_parent for root  */
        } while (!dentry_is_root(d));
index f1962d9884b63752892217f3eed71b29393a777c..ae9b8cea55e7ea7fde64de03e5cfbcedb703a4fe 100644 (file)
@@ -156,7 +156,9 @@ unix_build_extraction_path(const struct wim_dentry *dentry,
        d = dentry;
        do {
                p -= d->d_extraction_name_nchars;
        d = dentry;
        do {
                p -= d->d_extraction_name_nchars;
-               memcpy(p, d->d_extraction_name, d->d_extraction_name_nchars);
+               if (d->d_extraction_name_nchars)
+                       memcpy(p, d->d_extraction_name,
+                              d->d_extraction_name_nchars);
                *--p = '/';
                d = d->d_parent;
        } while (!dentry_is_root(d) && will_extract_dentry(d));
                *--p = '/';
                d = d->d_parent;
        } while (!dentry_is_root(d) && will_extract_dentry(d));
index c31d266841700f029a674dc1ea4b06577ebca503..cb488a9f6ed656013b74b67cacbf74b6c63914af 100644 (file)
@@ -901,7 +901,9 @@ build_extraction_path(const struct wim_dentry *dentry,
             d = d->d_parent)
        {
                p -= d->d_extraction_name_nchars;
             d = d->d_parent)
        {
                p -= d->d_extraction_name_nchars;
-               wmemcpy(p, d->d_extraction_name, d->d_extraction_name_nchars);
+               if (d->d_extraction_name_nchars)
+                       wmemcpy(p, d->d_extraction_name,
+                               d->d_extraction_name_nchars);
                *--p = '\\';
        }
        /* No leading slash  */
                *--p = '\\';
        }
        /* No leading slash  */