Whamcloud - gitweb
libext2fs: fix UBSan when updating an inline_data file
authorTheodore Ts'o <tytso@mit.edu>
Mon, 4 Nov 2019 23:43:49 +0000 (18:43 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 4 Nov 2019 23:43:49 +0000 (18:43 -0500)
What memcpy does when the length is zero is not well-defined.  So
avoid it.

Bug: https://github.com/tytso/e2fsprogs/issues/25
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/ext_attr.c

index 78a823a..affc1a8 100644 (file)
@@ -1550,14 +1550,15 @@ errcode_t ext2fs_xattr_set(struct ext2_xattr_handle *h,
                                                       new_value, &value_len);
                if (ret)
                        goto out;
-       } else
+       } else if (value_len)
                memcpy(new_value, value, value_len);
 
        /* Imitate kernel behavior by skipping update if value is the same. */
        for (x = h->attrs; x < h->attrs + h->count; x++) {
                if (!strcmp(x->name, name)) {
                        if (!x->ea_ino && x->value_len == value_len &&
-                           !memcmp(x->value, new_value, value_len)) {
+                           (!value_len ||
+                            !memcmp(x->value, new_value, value_len))) {
                                ret = 0;
                                goto out;
                        }