From patchwork Wed Jul 26 08:49:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 73216 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AA2A8385770A for ; Wed, 26 Jul 2023 08:49:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AA2A8385770A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690361390; bh=4yc//7tauhox5AloAW5vR1/08HkmtEwDwcG2vFFDxns=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=aOeZmFa7snxfNKYV3Jcfw4OMHPKvax+/GaCOAylMqO1MCArnCjTgOSS/p5aLeo0QP zjKsa0yAXJkuzbOSQbBI6/JRNz/w8JSc21p1nKHxGyQgug0UopbUIAPGZtAf94wDJq 2hzwKVHIVgZcl6zAW80wefB0CnrLWkA9KGiiQoRs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 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) 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 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 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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(-) base-commit: 477c9f2ba26ccd77016f2c97941fc8b35e332e35 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); }