e2fsprogs/SOURCES/e2fsprogs-1.45.5-libext2fs-fix-UBSan-when-updating-an-inline_data-fil.patch

40 lines
1.2 KiB
Diff
Raw Normal View History

2020-04-23 22:07:34 +00:00
From bee65149cc025522ae0e2c37a0ce817641ebac28 Mon Sep 17 00:00:00 2001
From: Theodore Ts'o <tytso@mit.edu>
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 <tytso@mit.edu>
---
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