From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29053 invoked by alias); 21 Jan 2020 15:53:24 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 28982 invoked by uid 89); 21 Jan 2020 15:53:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.3 required=5.0 tests=AWL,BAYES_00,FORGED_SPF_HELO,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: sa-prd-fep-041.btinternet.com Received: from mailomta6-sa.btinternet.com (HELO sa-prd-fep-041.btinternet.com) (213.120.69.12) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Jan 2020 15:53:13 +0000 Received: from sa-prd-rgout-004.btmx-prd.synchronoss.net ([10.2.38.7]) by sa-prd-fep-041.btinternet.com with ESMTP id <20200121155311.GZPE8303.sa-prd-fep-041.btinternet.com@sa-prd-rgout-004.btmx-prd.synchronoss.net>; Tue, 21 Jan 2020 15:53:11 +0000 Authentication-Results: btinternet.com; none X-OWM-Source-IP: 31.51.207.12 (GB) X-OWM-Env-Sender: jonturney@btinternet.com X-VadeSecure-score: verdict=clean score=0/300, class=clean Received: from localhost.localdomain (31.51.207.12) by sa-prd-rgout-004.btmx-prd.synchronoss.net (5.8.337) (authenticated as jonturney@btinternet.com) id 5E1A2CBA01996DF7; Tue, 21 Jan 2020 15:53:11 +0000 From: Jon Turney To: binutils@sourceware.org Cc: Jon Turney Subject: [PATCH 1/3] Bugfixes for pe_print_debugdata() Date: Tue, 21 Jan 2020 15:53:00 -0000 Message-Id: <20200121155212.12686-2-jon.turney@dronecode.org.uk> In-Reply-To: <20200121155212.12686-1-jon.turney@dronecode.org.uk> References: <20200121155212.12686-1-jon.turney@dronecode.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SW-Source: 2020-01/txt/msg00301.txt.bz2 Use a separate iteration variable for inner loop (:blush:). This generally prevented any debug directory entries after a IMAGE_DEBUG_TYPE_CODEVIEW entry from being reported. Don't leak the memory allocated for the section containing the debug directory. bfd/ChangeLog: 2020-01-16 Jon Turney * peXXigen.c (pe_print_debugdata): Fix the iteration variable for inner loop. Fix a memory leak. --- bfd/ChangeLog | 5 +++++ bfd/peXXigen.c | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c index c5082a7dee..ac0cf17464 100644 --- a/bfd/peXXigen.c +++ b/bfd/peXXigen.c @@ -2630,7 +2630,7 @@ pe_print_debugdata (bfd * abfd, void * vfile) asection *section; bfd_byte *data = 0; bfd_size_type dataoff; - unsigned int i; + unsigned int i, j; bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress; bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size; @@ -2722,8 +2722,8 @@ pe_print_debugdata (bfd * abfd, void * vfile) idd.SizeOfData, cvinfo)) continue; - for (i = 0; i < cvinfo->SignatureLength; i++) - sprintf (&signature[i*2], "%02x", cvinfo->Signature[i] & 0xff); + for (j = 0; j < cvinfo->SignatureLength; j++) + sprintf (&signature[j*2], "%02x", cvinfo->Signature[j] & 0xff); /* xgettext:c-format */ fprintf (file, _("(format %c%c%c%c signature %s age %ld)\n"), @@ -2732,6 +2732,8 @@ pe_print_debugdata (bfd * abfd, void * vfile) } } + free(data); + if (size % sizeof (struct external_IMAGE_DEBUG_DIRECTORY) != 0) fprintf (file, _("The debug directory size is not a multiple of the debug directory entry size\n")); -- 2.21.0