]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Do not assume ELF in dwarf2/read.c
authorTom Tromey <tromey@adacore.com>
Wed, 21 Aug 2024 15:09:26 +0000 (09:09 -0600)
committerTom Tromey <tromey@adacore.com>
Wed, 21 Aug 2024 16:33:46 +0000 (10:33 -0600)
dwarf2/read.c has this code:

  else if (elf_section_data (sectp)->this_hdr.sh_size
   > bfd_get_file_size (abfd))

This assumes that the BFD is an ELF, which is an invalid assumption.
A user noticed that this can sometimes cause a crash.

This patch fixes the problem by changing this code to use
bfd_section_size_insane.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32104
Reviewed-By: Tom de Vries <tdevries@suse.de>
Reviewed-by: Keith Seitz <keiths@redhat.com>
gdb/dwarf2/read.c

index fde8eee62762ac528181091cc386be9eb24e9b8c..f9f34fd4c38a17cf65973835a3ae6696c41706b2 100644 (file)
@@ -1423,12 +1423,11 @@ dwarf2_per_bfd::locate_sections (bfd *abfd, asection *sectp,
   if ((aflag & SEC_HAS_CONTENTS) == 0)
     {
     }
-  else if (elf_section_data (sectp)->this_hdr.sh_size
-          > bfd_get_file_size (abfd))
+  else if (bfd_section_size_insane (abfd, sectp))
     {
-      bfd_size_type size = elf_section_data (sectp)->this_hdr.sh_size;
-      warning (_("Discarding section %s which has a section size (%s"
-                ") larger than the file size [in module %s]"),
+      bfd_size_type size = sectp->size;
+      warning (_("Discarding section %s which has an invalid size (%s) "
+                "[in module %s]"),
               bfd_section_name (sectp), phex_nz (size, sizeof (size)),
               bfd_get_filename (abfd));
     }