From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id ECEF53858412 for ; Thu, 6 Apr 2023 15:04:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECEF53858412 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 r6.localdomain (82-217-174-174.cable.dynamic.v4.ziggo.nl [82.217.174.174]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id A970B302BB02; Thu, 6 Apr 2023 17:04:19 +0200 (CEST) Received: by r6.localdomain (Postfix, from userid 1000) id B2DBC340082; Thu, 6 Apr 2023 17:04:18 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH] readelf: Handle NULL shdr in section_name Date: Thu, 6 Apr 2023 17:04:08 +0200 Message-Id: <20230406150408.476447-1-mark@klomp.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3035.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,RCVD_IN_BARRACUDACENTRAL,SPF_HELO_NONE,SPF_PASS,TXREP 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: In some error cases we want to show the section name but cannot because the section header is corrupt or NULL. Make sure the section_name always returns "???" in that case. * src/readelf.c (section_name): Check for shdr == NULL. Signed-off-by: Mark Wielaard --- src/readelf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/readelf.c b/src/readelf.c index 6950204e..4a1b985d 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -1606,7 +1606,7 @@ static const char * section_name (Ebl *ebl, GElf_Shdr *shdr) { size_t shstrndx; - if (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0) + if (shdr == NULL || elf_getshdrstrndx (ebl->elf, &shstrndx) < 0) return "???"; return elf_strptr (ebl->elf, shstrndx, shdr->sh_name) ?: "???"; } -- 2.39.2