From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 7E94A3858C33 for ; Wed, 26 Jul 2023 08:49:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7E94A3858C33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4E42E21DF1 for ; Wed, 26 Jul 2023 08:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1690361365; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=4yc//7tauhox5AloAW5vR1/08HkmtEwDwcG2vFFDxns=; b=EbtqXEkn2KYzP+bsXqa0b0VclgGQLgAoskaa7bHBeYYwCo7yWjBX7xyvyxio8WTf106Wa1 AmcYFQJaw+ioOb4KT7/0Q2p9Sh79BrFOua33k1Fvrr7lvjbqTnsDVdjvw48dDlLNRONbHh sJYXjOQjMhqmO5E4FKcwI5LaK6t6XpQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1690361365; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=4yc//7tauhox5AloAW5vR1/08HkmtEwDwcG2vFFDxns=; b=BUIixmuL8wNM94t+lFnulGDKhwGgFWJutofo0VwWqgd24rNt6ZMow8880lKA49UGwGfMDI VN8p+upQYRet8gDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3AE7E139BD for ; Wed, 26 Jul 2023 08:49:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id bV0oDRXewGQwUQAAMHmgww (envelope-from ) for ; Wed, 26 Jul 2023 08:49:25 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/build] Fix Wstringop-truncation in coff_getfilename Date: Wed, 26 Jul 2023 10:49:09 +0200 Message-Id: <20230726084909.32090-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: When building gdb with -O2 -fsanitize-threads, I ran into a Werror=stringop-truncation. The problem is here in coff_getfilename in coffread.c: ... strncpy (buffer, aux_entry->x_file.x_n.x_fname, FILNMLEN); buffer[FILNMLEN] = '\0'; ... The constant FILNMLEN is expected to designate the size of aux_entry->x_file.x_n.x_fname, but that's no longer the case since commit 60ebc257517 ("Fixes a buffer overflow when compiling assembler for the MinGW targets."). Fix this by using "sizeof (aux_entry->x_file.x_n.x_fname)" instead. Likewise in xcoffread.c. Tested on x86_64-linux. PR build/30669 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30669 --- gdb/coffread.c | 5 +++-- gdb/xcoffread.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/gdb/coffread.c b/gdb/coffread.c index 33fb2ba1fca..6ec341c61c2 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -1371,8 +1371,9 @@ coff_getfilename (union internal_auxent *aux_entry) } else { - strncpy (buffer, aux_entry->x_file.x_n.x_fname, FILNMLEN); - buffer[FILNMLEN] = '\0'; + size_t x_fname_len = sizeof (aux_entry->x_file.x_n.x_fname); + strncpy (buffer, aux_entry->x_file.x_n.x_fname, x_fname_len); + buffer[x_fname_len] = '\0'; } result = buffer; diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 1538d1c823d..8930cf1bc35 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -1598,8 +1598,9 @@ coff_getfilename (union internal_auxent *aux_entry, struct objfile *objfile) + aux_entry->x_file.x_n.x_n.x_offset)); else { - strncpy (buffer, aux_entry->x_file.x_n.x_fname, FILNMLEN); - buffer[FILNMLEN] = '\0'; + size_t x_fname_len = sizeof (aux_entry->x_file.x_n.x_fname); + strncpy (buffer, aux_entry->x_file.x_n.x_fname, x_fname_len); + buffer[x_fname_len] = '\0'; } return (buffer); } base-commit: 477c9f2ba26ccd77016f2c97941fc8b35e332e35 -- 2.35.3