From patchwork Thu Jan 2 12:54:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Turney X-Patchwork-Id: 37155 Received: (qmail 33807 invoked by alias); 2 Jan 2020 12:54:43 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 33798 invoked by uid 89); 2 Jan 2020 12:54:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.6 required=5.0 tests=AWL, BAYES_50, EXECUTABLE_URI, FORGED_SPF_HELO, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_EXEURI, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=sk:jontur, Turney, sk:jon.tur, jon X-HELO: sa-prd-fep-049.btinternet.com Received: from mailomta6-sa.btinternet.com (HELO sa-prd-fep-049.btinternet.com) (213.120.69.12) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 02 Jan 2020 12:54:41 +0000 Received: from sa-prd-rgout-005.btmx-prd.synchronoss.net ([10.2.38.8]) by sa-prd-fep-049.btinternet.com with ESMTP id <20200102125438.TUCW28776.sa-prd-fep-049.btinternet.com@sa-prd-rgout-005.btmx-prd.synchronoss.net>; Thu, 2 Jan 2020 12:54:38 +0000 Authentication-Results: btinternet.com; auth=pass (LOGIN) smtp.auth=jonturney@btinternet.com 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-005.btmx-prd.synchronoss.net (5.8.337) (authenticated as jonturney@btinternet.com) id 5D8362CD127CA6E2; Thu, 2 Jan 2020 12:54:38 +0000 From: Jon Turney To: gdb-patches@sourceware.org Cc: Jon Turney Subject: [PATCH] Fix a crash with a malformed PE header Date: Thu, 2 Jan 2020 12:54:05 +0000 Message-Id: <20200102125405.11499-1-jon.turney@dronecode.org.uk> MIME-Version: 1.0 Don't try to read the PE export table when no section contains the RVA for it. (I have a PE executable [1] packed with UPX, where the export table data directory entry contains a RVA which doesn't correspond to any section. Mistakenly trying to debug this with gdb makes it crash.) [1] https://cygwin.com/setup/setup-2.898.x86_64.exe gdb/ChangeLog: 2020-01-02 Jon Turney * coff-pe-read.c (read_pe_exported_syms): Don't try to read the export table if no section contains it's RVA. --- gdb/ChangeLog | 5 +++++ gdb/coff-pe-read.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c index b05357bb8b..305900cfa3 100644 --- a/gdb/coff-pe-read.c +++ b/gdb/coff-pe-read.c @@ -441,6 +441,12 @@ read_pe_exported_syms (minimal_symbol_reader &reader, } } + if (expptr == 0) + { + /* no section contains export table rva */ + return; + } + export_rva = export_opthdrrva; export_size = export_opthdrsize;