]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf.c: Check debug section data before trying to print abbrev or str.
authorMark Wielaard <mjw@redhat.com>
Wed, 28 Mar 2012 09:20:36 +0000 (11:20 +0200)
committerMark Wielaard <mjw@redhat.com>
Wed, 28 Mar 2012 17:56:02 +0000 (19:56 +0200)
* readelf.c (print_debug_abbrev_section): Check there is Dwarf
section data.
(print_debug_str_section): Likewise.

src/ChangeLog
src/readelf.c

index 62817567f91a71b5bcfc2d356ba8f0f9d75335d0..30be3e1327b37ab2029f93a58ca38f6bb7447f63 100644 (file)
@@ -1,3 +1,9 @@
+2012-03-28  Mark Wielaard  <mjw@redhat.com>
+
+       * readelf.c (print_debug_abbrev_section): Check there is Dwarf
+       section data.
+       (print_debug_str_section): Likewise.
+
 2012-03-21  Mark Wielaard  <mjw@redhat.com>
 
        * readelf.c (print_gdb_index_section): Accept version 6.
index f9f56aadaa28024b39c6ecc00cb26b947c7727c2..b70779dd92462a21142d3d2430e0b465e698fe7f 100644 (file)
@@ -4566,13 +4566,16 @@ print_debug_abbrev_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
                            Ebl *ebl, GElf_Ehdr *ehdr,
                            Elf_Scn *scn, GElf_Shdr *shdr, Dwarf *dbg)
 {
+  const size_t sh_size = (dbg->sectiondata[IDX_debug_abbrev] ?
+                         dbg->sectiondata[IDX_debug_abbrev]->d_size : 0);
+
   printf (gettext ("\nDWARF section [%2zu] '%s' at offset %#" PRIx64 ":\n"
                   " [ Code]\n"),
          elf_ndxscn (scn), section_name (ebl, ehdr, shdr),
          (uint64_t) shdr->sh_offset);
 
   Dwarf_Off offset = 0;
-  while (offset < dbg->sectiondata[IDX_debug_abbrev]->d_size)
+  while (offset < sh_size)
     {
       printf (gettext ("\nAbbreviation section at offset %" PRIu64 ":\n"),
              offset);
@@ -6781,7 +6784,8 @@ print_debug_str_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
                         Ebl *ebl, GElf_Ehdr *ehdr,
                         Elf_Scn *scn, GElf_Shdr *shdr, Dwarf *dbg)
 {
-  const size_t sh_size = dbg->sectiondata[IDX_debug_str]->d_size;
+  const size_t sh_size = (dbg->sectiondata[IDX_debug_str] ?
+                         dbg->sectiondata[IDX_debug_str]->d_size : 0);
 
   /* Compute floor(log16(shdr->sh_size)).  */
   GElf_Addr tmp = sh_size;