public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tom@tromey.com>
Cc: Aaron Merey <amerey@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/dwarf2: Check for missing abbrev
Date: Thu, 14 Mar 2024 09:56:18 -0400	[thread overview]
Message-ID: <22883d8d-b634-4e71-802c-239114d01279@simark.ca> (raw)
In-Reply-To: <878r2lm1un.fsf@tromey.com>



On 2024-03-14 08:31, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:
> 
> Simon> However, I'd like if we could analyze the problem a bit further to
> Simon> understand more precisely what happens, just to be sure that there isn't
> Simon> a more fundamental problem and we're not just papering over the problem.
> 
> The issue is corrupt DWARF -- the DIE specifies an abbrev that doesn't exist.

If it was an abbrev number that didn't exist, then peek_die_abbrev would
throw here:

  const abbrev_info *abbrev
    = reader.abbrev_table->lookup_abbrev (abbrev_number);
  if (!abbrev)
    {
      error (_("Dwarf Error: Could not find abbrev number %d in %s"
	       " at offset %s [in module %s]"),
	     abbrev_number, cu->per_cu->is_debug_types ? "TU" : "CU",
	     sect_offset_str (cu->header.sect_off), bfd_get_filename (abfd));
    }

If peek_die_abbrev returns nullptr, it's because it read abbrev number 0
specifically (which normally means "end of DIE list", but is unexpected
at this particular place).  So I'm just wondering what "kind" of
corruption causes it to be 0.  The concrete case I'm worried about is
the possibility that the file is truncated and we go read an offset that
is out of our buffer's bounds.  In that case, some bounds checking
should probably be added somehwere.  If the file is not truncated and
just contains a bunch of 0s where it shouldn't because debuginfod
crashed while writing it, then just erroring out in scan_attributes
(after the peek_die_abbrev call) is fine.

> Whether erroring here is the best result is harder to say.  For example,
> would it make more sense to terminate the scanning but still install any
> symbols seen before this point?
> 
> I tend to agree that this approach is ok, though.  If the file is
> corrupt it seems fine to lose a few symbols, or maybe even the whole
> thing.

I think that erroring out is fine, certainly better than crashing.

Simon

  reply	other threads:[~2024-03-14 13:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13 20:18 Aaron Merey
2024-03-14  1:39 ` Simon Marchi
2024-03-14 12:31   ` Tom Tromey
2024-03-14 13:56     ` Simon Marchi [this message]
2024-03-14 14:31       ` Tom Tromey
2024-03-14 17:45         ` Aaron Merey
2024-03-14 17:52           ` Simon Marchi
2024-03-14 12:29 ` Tom Tromey
2024-03-14 12:36 ` Tom Tromey

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=22883d8d-b634-4e71-802c-239114d01279@simark.ca \
    --to=simark@simark.ca \
    --cc=amerey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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).