libdw: Detect dwarf_formudata errors in dwarf_getmacros.
authorMark Wielaard <mjw@redhat.com>
Thu, 18 Jun 2015 08:38:12 +0000 (10:38 +0200)
committerMark Wielaard <mjw@redhat.com>
Fri, 19 Jun 2015 10:20:56 +0000 (12:20 +0200)
dwarf_formudata can return an error for bad DWARF. Don't ignore it.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libdw/ChangeLog
libdw/dwarf_getmacros.c

index 487e34a..577de92 100644 (file)
@@ -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.
index 740368e..a326e58 100644 (file)
@@ -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