aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam James <sam@gentoo.org>2023-01-06 03:06:50 +0000
committerSam James <sam@gentoo.org>2023-01-10 05:21:39 +0000
commit2a0dffbf0080dc74f82910a74f051d835cfd653f (patch)
tree095a6f7a997c628c6c3c6fc62d2254c47288e022
parentfix-gnustack: add 'set -x' in tests for easier debugging (diff)
downloadelfix-2a0dffbf0080dc74f82910a74f051d835cfd653f.tar.gz
elfix-2a0dffbf0080dc74f82910a74f051d835cfd653f.tar.bz2
elfix-2a0dffbf0080dc74f82910a74f051d835cfd653f.zip
install-xattr: avoid accessing empty storage
UBSAN reports: ``` install-xattr.c:124:16: runtime error: load of address 0x55555556d440 with insufficient space for an object of type 'char' 0x55555556d440: note: pointer points here 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 61 00 00 00 ^ #0 0x555555557a27 in copyxattr /home/sam/git/elfix/misc/install-xattr/install-xattr.c:124 #1 0x555555556a4d in main /home/sam/git/elfix/misc/install-xattr/install-xattr.c:410 #2 0x7ffff77c864f (/usr/lib64/libc.so.6+0x2364f) #3 0x7ffff77c8708 in __libc_start_main (/usr/lib64/libc.so.6+0x23708) #4 0x555555557114 in _start (/home/sam/git/elfix/misc/install-xattr/install-xattr+0x3114) ``` Triggered with: ``` mkdir /tmp/a touch /tmp/foo ./install-xattr -c /tmp/foo /tmp/foo2 /tmp/a ``` I don't see this with Clang or < GCC 12, but I do with GCC 13 (13.0.0_pre20230101 p5); I suspect it's because of object-size improvements. Signed-off-by: Sam James <sam@gentoo.org>
-rw-r--r--misc/install-xattr/install-xattr.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/misc/install-xattr/install-xattr.c b/misc/install-xattr/install-xattr.c
index 66530f9..db6dabd 100644
--- a/misc/install-xattr/install-xattr.c
+++ b/misc/install-xattr/install-xattr.c
@@ -119,6 +119,10 @@ copyxattr(const char *source, const char *target)
lxattr = xmalloc(lsize);
xlistxattr(source, lxattr, lsize);
+ /* There's no xattrs at all. */
+ if (lsize == 0)
+ return;
+
i = 0;
while (1) {
while (lxattr[i++] == 0)