From patchwork Thu Jan 26 13:58:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tremblay X-Patchwork-Id: 19034 Received: (qmail 124571 invoked by alias); 26 Jan 2017 13:59:12 -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 124559 invoked by uid 89); 26 Jan 2017 13:59:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=5417, H*f:sk:wwoka8a, H*MI:sk:wwoka8a, H*i:sk:wwoka8a X-HELO: usplmg21.ericsson.net Received: from usplmg21.ericsson.net (HELO usplmg21.ericsson.net) (198.24.6.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 26 Jan 2017 13:59:10 +0000 Received: from EUSAAHC001.ericsson.se (Unknown_Domain [147.117.188.75]) by (Symantec Mail Security) with SMTP id C3.81.02571.B3CA9885; Thu, 26 Jan 2017 08:58:54 +0100 (CET) Received: from elxa4wqvvz1.ca.am.ericsson.se (147.117.188.8) by smtps-am.internal.ericsson.com (147.117.188.75) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 26 Jan 2017 08:59:02 -0500 From: Antoine Tremblay To: , CC: Antoine Tremblay Subject: [PATCH v2] Fix crash when loading a core with unexpected register section size Date: Thu, 26 Jan 2017 08:58:54 -0500 Message-ID: <1485439134-17162-1-git-send-email-antoine.tremblay@ericsson.com> In-Reply-To: References: MIME-Version: 1.0 X-IsSubscribed: yes When loading a core without an executable like so: $ gdb --core core for example often the gdbarch won't contain the iterate_over_regset_sections method. For example arch-arm. This will generate a call to get_core_register_section with a NULL regset like at corelow.c:628 get_core_register_section (regcache, NULL, ".reg", 0, 0, "general-purpose", 1); However a check for REGSET_VARIABLE_SIZE in get_core_register_section assumes that regset is != NULL thus leading to a crash with this backtrace: (gdb) bt #0 0x000000000065907b in get_core_register_section (regcache=regcache@entry=0x2c26260, regset=regset@entry=0x0, name=name@entry=0xdbf7b2 ".reg", min_size=min_size@entry=0, which=which@entry=0, human_name=human_name@entry=0xdbac28 "general-purpose", required=1) at ../../gdb/corelow.c:542 #1 0x0000000000659b70 in get_core_registers (ops=, regcache=0x2c26260, regno=) at ../../gdb/corelow.c:628 #2 0x000000000076e5fb in target_fetch_registers (regcache=regcache@entry=0x2c26260, regno=regno@entry=15) at ../../gdb/target.c:3590 Note that commit: f962539ad23759 ("Warn if core file register section is larger than expected") introduced this issue. Thus releases > 7.8.2 are affected. This patch fixes this crash by adding a check for regset existence before running the condition. gdb/ChangeLog: * corelow.c (get_core_register_section): Check for regset existence before checking for REGSET_VARIABLE_SIZE. --- gdb/corelow.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gdb/corelow.c b/gdb/corelow.c index a075d9e..ecde954 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -515,6 +515,8 @@ get_core_register_section (struct regcache *regcache, struct bfd_section *section; bfd_size_type size; char *contents; + bool variable_size_section = (regset != NULL + && regset->flags & REGSET_VARIABLE_SIZE); xfree (section_name); @@ -539,7 +541,7 @@ get_core_register_section (struct regcache *regcache, warning (_("Section `%s' in core file too small."), section_name); return; } - if (size != min_size && !(regset->flags & REGSET_VARIABLE_SIZE)) + if (size != min_size && !variable_size_section) { warning (_("Unexpected size of section `%s' in core file."), section_name);