From bee65149cc025522ae0e2c37a0ce817641ebac28 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 4 Nov 2019 18:43:49 -0500 Subject: [PATCH 02/10] libext2fs: fix UBSan when updating an inline_data file 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 --- lib/ext2fs/ext_attr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c index 78a823a9..affc1a8f 100644 --- a/lib/ext2fs/ext_attr.c +++ b/lib/ext2fs/ext_attr.c @@ -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; } -- 2.21.1