This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] libdw: Detect dwarf_formudata errors in dwarf_getmacros.


dwarf_formudata can return an error for bad DWARF. Don't ignore it.

Signed-off-by: Mark Wielaard <mjw@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@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@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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]