From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 99251 invoked by alias); 26 Jan 2017 13:40:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 99216 invoked by uid 89); 26 Jan 2017 13:40:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.1 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Tremblay, tremblay, H*i:sk:1485436, Antoine X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 26 Jan 2017 13:40:20 +0000 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E7F27FB67; Thu, 26 Jan 2017 13:40:20 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id A710EBB00A; Thu, 26 Jan 2017 13:40:19 +0000 (UTC) Subject: Re: [PATCH] Fix crash when loading a core with unexpected register section size To: Antoine Tremblay , gdb-patches@sourceware.org References: <1485436646-12223-1-git-send-email-antoine.tremblay@ericsson.com> From: Pedro Alves Message-ID: <3c0fb039-513d-9c8a-5851-e13a32d3d3ea@redhat.com> Date: Thu, 26 Jan 2017 13:40:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <1485436646-12223-1-git-send-email-antoine.tremblay@ericsson.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-01/txt/msg00566.txt.bz2 On 01/26/2017 01:17 PM, Antoine Tremblay wrote: > 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. Can you give an example? That'd help a lot understand the issue better. Also, please add a line break, ""s and/or punctuation to make the command stand out more from the rest of the sentence. For example: 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-foo. > > 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: f962539ad23759af4ba8f7eece1946fdc2f5087 Please always paste the commit's subject as well, to make it easier for us poor humans to quickly tell what the commit was about without having to go to a terminal. The Linux guideline is to put it in parens: Note that commit f962539ad23759 ("Warn if core file register section is larger than expected") introduced [...] I personally like that style. introcuded this (typo) > 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 > existance before checking for REGSET_VARIABLE_SIZE. Indentation. "existence". > --- > gdb/corelow.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/gdb/corelow.c b/gdb/corelow.c > index a075d9e..f43f730 100644 > --- a/gdb/corelow.c > +++ b/gdb/corelow.c > @@ -515,6 +515,7 @@ get_core_register_section (struct regcache *regcache, > struct bfd_section *section; > bfd_size_type size; > char *contents; > + bool variable_size_section = false; No need to initialize by default when you're always going to initialize it again below. Or declare on first use and avoid the issue entirely. Thanks, Pedro Alves