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 BD418385803E for ; Thu, 24 Mar 2022 17:09:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BD418385803E 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 tarox.wildebeest.org (83-87-18-245.cable.dynamic.v4.ziggo.nl [83.87.18.245]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id D42F7302FB81; Thu, 24 Mar 2022 18:09:27 +0100 (CET) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id C304D413CEB2; Thu, 24 Mar 2022 18:09:26 +0100 (CET) From: Mark Wielaard To: debugedit@sourceware.org Cc: Mark Wielaard Subject: [COMMITTED] debugedit: Guard against NULL names returned by by strptr Date: Thu, 24 Mar 2022 18:09:23 +0100 Message-Id: <20220324170923.28445-1-mark@klomp.org> X-Mailer: git-send-email 2.18.4 X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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, 24 Mar 2022 17:09:31 -0000 debugedit.c (edit_dwarf2): Check name is not NULL before calling strncmp. (main): Check name is not NULL before calling strcmp. This is unlikely to happen, except when the ELF file is corrupt. Signed-off-by: Mark Wielaard --- tools/debugedit.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/debugedit.c b/tools/debugedit.c index 642b29d..e734dd7 100644 --- a/tools/debugedit.c +++ b/tools/debugedit.c @@ -2586,7 +2586,8 @@ edit_dwarf2 (DSO *dso) const char *name = strptr (dso, dso->ehdr.e_shstrndx, dso->shdr[i].sh_name); - if (strncmp (name, ".debug_", sizeof (".debug_") - 1) == 0) + if (name != NULL + && strncmp (name, ".debug_", sizeof (".debug_") - 1) == 0) { for (j = 0; debug_sections[j].name; ++j) if (strcmp (name, debug_sections[j].name) == 0) @@ -2642,9 +2643,11 @@ edit_dwarf2 (DSO *dso) } else if (dso->ehdr.e_type == ET_REL && ((dso->shdr[i].sh_type == SHT_REL + && name != NULL && strncmp (name, ".rel.debug_", sizeof (".rel.debug_") - 1) == 0) || (dso->shdr[i].sh_type == SHT_RELA + && name != NULL && strncmp (name, ".rela.debug_", sizeof (".rela.debug_") - 1) == 0))) { @@ -3467,13 +3470,13 @@ main (int argc, char *argv[]) case SHT_PROGBITS: name = strptr (dso, dso->ehdr.e_shstrndx, dso->shdr[i].sh_name); /* TODO: Handle stabs */ - if (strcmp (name, ".stab") == 0) + if (name != NULL && strcmp (name, ".stab") == 0) { error (0, 0, "Stabs debuginfo not supported: %s", file); break; } if (!(do_build_id && no_recompute_build_id && !base_dir && !dest_dir) - && strcmp (name, ".debug_info") == 0) + && name != NULL && strcmp (name, ".debug_info") == 0) edit_dwarf2 (dso); break; -- 2.18.4