From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id A57C415800F for ; Tue, 10 Jan 2023 05:21:45 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9131EE07E6; Tue, 10 Jan 2023 05:21:44 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 797CAE07E6 for ; Tue, 10 Jan 2023 05:21:44 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 8D358340E16 for ; Tue, 10 Jan 2023 05:21:43 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 266D0824 for ; Tue, 10 Jan 2023 05:21:42 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1673328099.2a0dffbf0080dc74f82910a74f051d835cfd653f.sam@gentoo> Subject: [gentoo-commits] proj/elfix:master commit in: misc/install-xattr/ X-VCS-Repository: proj/elfix X-VCS-Files: misc/install-xattr/install-xattr.c X-VCS-Directories: misc/install-xattr/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 2a0dffbf0080dc74f82910a74f051d835cfd653f X-VCS-Branch: master Date: Tue, 10 Jan 2023 05:21:42 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 264c0b8b-b5a5-4f97-a6b0-32e084812a21 X-Archives-Hash: eb984c2460d988247fed14ee897fa195 commit: 2a0dffbf0080dc74f82910a74f051d835cfd653f Author: Sam James gentoo org> AuthorDate: Fri Jan 6 03:06:50 2023 +0000 Commit: Sam James gentoo org> CommitDate: Tue Jan 10 05:21:39 2023 +0000 URL: https://gitweb.gentoo.org/proj/elfix.git/commit/?id=2a0dffbf 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 gentoo.org> misc/install-xattr/install-xattr.c | 4 ++++ 1 file changed, 4 insertions(+) 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)