Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Antoine Tremblay <antoine.tremblay@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Antoine Tremblay <antoine.tremblay@ericsson.com>
Subject: [PATCH] Fix crash when loading a core with unexpected register section size
Date: Thu, 26 Jan 2017 13:17:00 -0000	[thread overview]
Message-ID: <1485436646-12223-1-git-send-email-antoine.tremblay@ericsson.com> (raw)

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.

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=<optimized out>,
    regcache=0x2c26260, regno=<optimized out>) 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 introcuded 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
                   existance before checking for REGSET_VARIABLE_SIZE.
---
 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;
 
   xfree (section_name);
 
@@ -534,12 +535,16 @@ get_core_register_section (struct regcache *regcache,
     }
 
   size = bfd_section_size (core_bfd, section);
+
+  variable_size_section = (regset != NULL
+			   && regset->flags & REGSET_VARIABLE_SIZE);
+
   if (size < min_size)
     {
       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);
-- 
2.7.4


             reply	other threads:[~2017-01-26 13:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-26 13:17 Antoine Tremblay [this message]
2017-01-26 13:40 ` Pedro Alves
2017-01-26 13:56   ` Antoine Tremblay
2017-01-26 13:59     ` [PATCH v2] " Antoine Tremblay
2017-01-26 14:25     ` [PATCH] " Pedro Alves
2017-01-26 14:31       ` Antoine Tremblay
2017-01-26 14:35         ` Pedro Alves
2017-01-26 14:59           ` Antoine Tremblay
2017-01-26 15:20             ` Pedro Alves
2017-01-26 15:27               ` Antoine Tremblay
2017-01-26 15:53               ` [pushed][PATCH v2] " Antoine Tremblay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1485436646-12223-1-git-send-email-antoine.tremblay@ericsson.com \
    --to=antoine.tremblay@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox