[COMMITTED] readelf: Fix crash on reading loc data or range data with bad/no CUs.
Mark Wielaard
mark@klomp.org
Thu Jan 25 13:35:00 GMT 2018
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 | 5 +++++
src/readelf.c | 4 ++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/ChangeLog b/src/ChangeLog
index 49b0cc0..a0bb7a2 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -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.
diff --git a/src/readelf.c b/src/readelf.c
index 4bdaef2..6c49d30 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,
--
1.8.3.1
More information about the Elfutils-devel
mailing list