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 17B023856247 for ; Tue, 10 May 2022 10:35:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 17B023856247 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 B6ED93000599; Tue, 10 May 2022 12:35:03 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 38F0F400E905; Tue, 10 May 2022 12:35:03 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH] elfcompress: Add sanity checks to make sure to not override variable Date: Tue, 10 May 2022 12:35:01 +0200 Message-Id: <20220510103501.30432-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: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 May 2022 10:35:06 -0000 The process_file code is a little tricky. Add sanity checks to make sure shstrtab_name, shstrtab_newname and symstrents are only set once. Signed-off-by: Mark Wielaard --- src/ChangeLog | 5 +++++ src/elfcompress.c | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/ChangeLog b/src/ChangeLog index b978f9ef..d08381e8 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2022-05-10 Mark Wielaard + + * elfcompress.c (process_file): Sanity check shstrtab_name, + shstrtab_newname and symstrents are only set once. + 2022-05-09 Mark Wielaard * strip.c (remove_debug_relocations): Check gelf_getshdr, gelf_getrela, diff --git a/src/elfcompress.c b/src/elfcompress.c index 92f2fac8..6f18e47d 100644 --- a/src/elfcompress.c +++ b/src/elfcompress.c @@ -730,6 +730,15 @@ process_file (const char *fname) { shstrtab_size = size; shstrtab_compressed = T_COMPRESS_GNU; + if (shstrtab_name != NULL + || shstrtab_newname != NULL) + { + error (0, 0, "Internal error," + " shstrtab_name already set," + " while handling section [%zd] %s", + ndx, sname); + goto cleanup; + } shstrtab_name = xstrdup (sname); shstrtab_newname = xstrdup (newname); } @@ -786,6 +795,15 @@ process_file (const char *fname) { shstrtab_size = size; shstrtab_compressed = T_COMPRESS_ZLIB; + if (shstrtab_name != NULL + || shstrtab_newname != NULL) + { + error (0, 0, "Internal error," + " shstrtab_name already set," + " while handling section [%zd] %s", + ndx, sname); + goto cleanup; + } shstrtab_name = xstrdup (sname); shstrtab_newname = (newname == NULL ? NULL : xstrdup (newname)); @@ -919,6 +937,12 @@ process_file (const char *fname) } size_t elsize = gelf_fsize (elfnew, ELF_T_SYM, 1, EV_CURRENT); size_t syms = symd->d_size / elsize; + if (symstrents != NULL) + { + error (0, 0, "Internal error, symstrents already set," + " while handling section [%zd] %s", ndx, name); + goto cleanup; + } symstrents = xmalloc (syms * sizeof (Dwelf_Strent *)); for (size_t i = 0; i < syms; i++) { -- 2.18.4