dwarf_formudata can return an error for bad DWARF. Don't ignore it.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
libdw/ChangeLog | 6 ++++++
libdw/dwarf_getmacros.c | 6 ++++--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 487e34a..577de92 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,9 @@
+2015-06-18 Mark Wielaard <mjw(a)redhat.com>
+
+ * dwarf_getmacros.c (get_macinfo_table): Return NULL when
+ dwarf_formudata reports an error.
+ (get_table_for_offset): Likewise.
+
2015-06-08 Mark Wielaard <mjw(a)redhat.com>
* dwarf_getsrclines.c (read_srclines): Initialize dirarray early.
diff --git a/libdw/dwarf_getmacros.c b/libdw/dwarf_getmacros.c
index 740368e..a326e58 100644
--- a/libdw/dwarf_getmacros.c
+++ b/libdw/dwarf_getmacros.c
@@ -125,7 +125,8 @@ get_macinfo_table (Dwarf *dbg, Dwarf_Word macoff, Dwarf_Die *cudie)
= INTUSE(dwarf_attr) (cudie, DW_AT_stmt_list, &attr_mem);
Dwarf_Off line_offset = (Dwarf_Off) -1;
if (attr != NULL)
- INTUSE(dwarf_formudata) (attr, &line_offset);
+ if (unlikely (INTUSE(dwarf_formudata) (attr, &line_offset) != 0))
+ return NULL;
Dwarf_Macro_Op_Table *table = libdw_alloc (dbg, Dwarf_Macro_Op_Table,
macinfo_data_size, 1);
@@ -178,7 +179,8 @@ get_table_for_offset (Dwarf *dbg, Dwarf_Word macoff,
Dwarf_Attribute attr_mem, *attr
= INTUSE(dwarf_attr) (cudie, DW_AT_stmt_list, &attr_mem);
if (attr != NULL)
- INTUSE(dwarf_formudata) (attr, &line_offset);
+ if (unlikely (INTUSE(dwarf_formudata) (attr, &line_offset) != 0))
+ return NULL;
}
/* """The macinfo entry types defined in this standard may, but
--
1.8.3.1
Show replies by date
Nested if gets hard to read fast. I usually prefer either && or braces
around the inner if. But it's fine as is.
On Thu, 2015-06-18 at 11:21 -0700, Roland McGrath wrote:
Nested if gets hard to read fast. I usually prefer either &&
or braces
around the inner if. But it's fine as is.
I left it as is because it is a simple test/return NULL in this case.
But agreed in general.
Thanks. Pushed.