public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] gdb: avoid nullptr access in dbxread.c from read_dbx_symtab
Date: Mon, 21 Feb 2022 11:51:18 +0000	[thread overview]
Message-ID: <87k0docua1.fsf@redhat.com> (raw)
In-Reply-To: <1eb38e94-5132-af9a-29a8-5810cf9a5eab@polymtl.ca>

Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

> On 2022-02-19 14:51, Andrew Burgess via Gdb-patches wrote:
>> This fixes a GDB crash reported in bug pr/28900, related to reading in
>> some stabs debug information.
>> 
>> In this commit my goal is to stop GDB crashing.  I am not trying to
>> ensure that GDB makes the best possible use of the available stabs
>> debug information.  At this point I consider stabs a legacy debug
>> format, with only limited support in GDB.
>> 
>> So, the problem appears to be that, when reading in the stabs data, we
>> need to find a N_SO entry, this is the entry that defines the start of
>> a compilation unit (or at least the location of a corresponding source
>> file).
>> 
>> It is while handling an N_SO that GDB creates a psymtab to hold the
>> incoming debug information (symbols, etc).
>> 
>> The problem we hit in the bug is that we encounter some symbol
>> information (an N_PC entry) outside of an N_SO entry - that is we find
>> some symbol information that is not associated with any source file.
>> 
>> We already have some protection for this case, look (in
>> read_dbx_symtab) at the handling of N_PC entries of type 'F' and 'f',
>> if we have no psymtab (the pst variable is nullptr) then we issue a
>> complaint.  However, for whatever reason, in both 'f' and 'F'
>> handling, there is one place where we assume that the pst
>> variable (the psymtab) is not nullptr.  This is a mistake.
>> 
>> In this commit, I guard these two locations (in 'f' and 'F' handling)
>> so we no longer assume pst is not nullptr.
>> 
>> While I was at it, I audited all the other uses of pst in
>> read_dbx_symtab, and in every potentially dangerous case I added a
>> nullptr check, and issue a suitable complaint if pst is found to be
>> nullptr.
>> 
>> It might well be true that we could/should do something smarter if we
>> see a debug symbol outside of an N_SO entry, and if anyone wanted to
>> do that work, they're welcome too.  But this commit is just about
>> preventing the nullptr access, and the subsequent GDB crash.
>> 
>> I don't have any tests for this change, I have no idea how to generate
>> weird stabs data for testing.  The original binary from the bug report
>> now loads just fine without GDB crashing.
>> 
>> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28900
>
> For all I know, this looks correct.  Thanks for doing this.

Thanks, I pushed this patch.

Andrew


      reply	other threads:[~2022-02-21 11:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-19 19:51 [PATCH 0/2] fix for the stabs debug parser Andrew Burgess
2022-02-19 19:51 ` [PATCH 1/2] gdb: make use of std::string in dbxread.c Andrew Burgess
2022-02-20  1:27   ` Simon Marchi
2022-02-21 11:50     ` Andrew Burgess
2022-02-19 19:51 ` [PATCH 2/2] gdb: avoid nullptr access in dbxread.c from read_dbx_symtab Andrew Burgess
2022-02-20  1:30   ` Simon Marchi
2022-02-21 11:51     ` Andrew Burgess [this message]

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=87k0docua1.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).