]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: Fix crash on reading loc data or range data with bad/no CUs.
authorMark Wielaard <mark@klomp.org>
Thu, 25 Jan 2018 12:24:19 +0000 (13:24 +0100)
committerMark Wielaard <mark@klomp.org>
Thu, 25 Jan 2018 12:58:26 +0000 (13:58 +0100)
In print_debug_ranges_section and print_debug_loc_section we try to
get the associated CU through skip_listptr_hole for the first data data.
If no CU at all can be found (because the .debug_info section was bogus)
this would keep the Dwarf_CU uninitialized causing a crash later on
when it was compared to the last_cu and used because it was unequal.
Fix this by explicitly initializing cu to last_cu (which is NULL on
first use).

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/readelf.c

index 49b0cc036706a7ebd1c7a9b3ffb8998b64d6ff6d..a0bb7a25736d448179ecee1b46ea6e02b6898c8a 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-25  Mark Wielaard  <mark@klomp.org>
+
+       * readelf.c (print_debug_ranges_section): Initialize cu to last_cu.
+       (print_debug_loc_section): Likewise.
+
 2018-01-01  Mark Wielaard  <mark@klomp.org>
 
        * readelf.c (attr_callback): Use dwarf_form_name for unknown forms.
index 4bdaef204eec0e06cfbc924545faa5a703c4a4c2..6c49d305a017729927628443edd8ea6259aea9dd 100644 (file)
@@ -5014,7 +5014,7 @@ print_debug_ranges_section (Dwfl_Module *dwflmod,
   while (readp < endp)
     {
       ptrdiff_t offset = readp - (unsigned char *) data->d_buf;
-      Dwarf_CU *cu;
+      Dwarf_CU *cu = last_cu;
 
       if (first && skip_listptr_hole (&known_rangelistptr, &listptr_idx,
                                      &address_size, NULL, &base, &cu,
@@ -7140,7 +7140,7 @@ print_debug_loc_section (Dwfl_Module *dwflmod,
   while (readp < endp)
     {
       ptrdiff_t offset = readp - (unsigned char *) data->d_buf;
-      Dwarf_CU *cu;
+      Dwarf_CU *cu = last_cu;
 
       if (first && skip_listptr_hole (&known_loclistptr, &listptr_idx,
                                      &address_size, &offset_size, &base,