From: Mark Wielaard Date: Thu, 25 Jan 2018 12:24:19 +0000 (+0100) Subject: readelf: Fix crash on reading loc data or range data with bad/no CUs. X-Git-Tag: elfutils-0.171~84 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e98f032d293a8ea8ea2b25949d7f452603e644d9;p=thirdparty%2Felfutils.git readelf: Fix crash on reading loc data or range data with bad/no CUs. 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 --- diff --git a/src/ChangeLog b/src/ChangeLog index 49b0cc036..a0bb7a257 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2018-01-25 Mark Wielaard + + * readelf.c (print_debug_ranges_section): Initialize cu to last_cu. + (print_debug_loc_section): Likewise. + 2018-01-01 Mark Wielaard * readelf.c (attr_callback): Use dwarf_form_name for unknown forms. diff --git a/src/readelf.c b/src/readelf.c index 4bdaef204..6c49d305a 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -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,