From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id 1E818396EC05 for ; Thu, 1 Jul 2021 14:15:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1E818396EC05 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from reform (deer0x00.wildebeest.org [172.31.17.130]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 142513000252; Thu, 1 Jul 2021 16:15:19 +0200 (CEST) Received: by reform (Postfix, from userid 1000) id 91B152E80F3E; Thu, 1 Jul 2021 16:15:19 +0200 (CEST) From: Mark Wielaard To: debugedit@sourceware.org Cc: Mark Wielaard Subject: [PATCH] sepdebugcrcfix: Don't crash if .gnu_debuglink doesn't contain a file string. Date: Thu, 1 Jul 2021 16:15:14 +0200 Message-Id: <20210701141514.325121-1-mark@klomp.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: debugedit@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: debugedit development mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jul 2021 14:15:24 -0000 If the .gnu_debuglink section didn't contain a valid file string then we would crash. Produce an error instead. * tools/sepdebugcrcfix.c (process): Produce an error when zerop is NULL. Signed-off-by: Mark Wielaard --- tools/sepdebugcrcfix.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/sepdebugcrcfix.c b/tools/sepdebugcrcfix.c index 20800ba..024d09c 100644 --- a/tools/sepdebugcrcfix.c +++ b/tools/sepdebugcrcfix.c @@ -258,10 +258,13 @@ process (Elf *elf, int fd, const char *fname) continue; } const uint8_t *zerop = memchr (data->d_buf, '\0', data->d_size); - const uint8_t *crcp = (zerop == NULL - ? NULL - : (const uint8_t *) ((uintptr_t) (zerop + 1 + 3) - & -4)); + if (zerop == NULL) + { + error (0, 0, _("no file string in section \"%s\" # %zu in \"%s\""), + scnname, elf_ndxscn (scn), fname); + continue; + } + const uint8_t *crcp = (const uint8_t *) ((uintptr_t) (zerop + 1 + 3) & -4); if (crcp + 4 != (uint8_t *) data->d_buf + data->d_size) { error (0, 0, _("invalid format of section \"%s\" # %zu in \"%s\""), -- 2.32.0