Re: [PATCH] [dwarf2read] Fix crash when loading dwp files: calculate num_sections based on actual section indices, not just the number of sections.

Jordan Rupprecht via gdb-patches
2019-02-25T21:22:07Z

[-- Attachment #1: Type: text/plain, Size: 1720 bytes --]

Thanks Simon!

On Mon, Feb 25, 2019 at 12:55 PM Simon Marchi <simon.marchi@polymtl.ca> wrote:
>
> On 2019-02-25 15:21, Jordan Rupprecht wrote:
> > Sorry, patch somehow didn't make it in the previous message. Including
> > it manually:
> >
> > ---
> > gdb/ChangeLog | 6 ++++++
> > gdb/dwarf2read.c | 3 +--
> > 2 files changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> > index 118f17588a..c2340e694c 100644
> > --- a/gdb/ChangeLog
> > +++ b/gdb/ChangeLog
> > @@ -1,3 +1,9 @@
> > +2019-02-25 Jordan Rupprecht <rupprecht@google.com>
> > +
> > + * dwarf2read.c (open_and_init_dwp_file): Call
> > + elf_numsections instead of bfd_count_sections to initialize
> > + dwp_file->num_sections.
> > +
> > 2019-02-25 Tom Tromey <tromey@adacore.com>
> >
> > * solib-darwin.c (darwin_get_dyld_bfd): Don't release dyld_bfd.
> > diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
> > index 98f46e0416..2908a233fe 100644
> > --- a/gdb/dwarf2read.c
> > +++ b/gdb/dwarf2read.c
> > @@ -13230,8 +13230,7 @@ open_and_init_dwp_file (struct
> > dwarf2_per_objfile *dwarf2_per_objfile)
> > std::unique_ptr<struct dwp_file> dwp_file
> > (new struct dwp_file (name, std::move (dbfd)));
> >
> > - /* +1: section 0 is unused */
> > - dwp_file->num_sections = bfd_count_sections (dwp_file->dbfd) + 1;
> > + dwp_file->num_sections = elf_numsections (dwp_file->dbfd);
> > dwp_file->elf_sections =
> > OBSTACK_CALLOC (&objfile->objfile_obstack,
> > dwp_file->num_sections, asection *);
> > --
> > 2.21.0.rc0.258.g878e2cd30e-goog
>
> I have tweaked the original commit message a bit and pushed.
>
> Thanks again for the patch.
>
> Simon

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4849 bytes --]