]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw: Don't pass NULL to dwarf_peel_type
authorMark Wielaard <mark@klomp.org>
Mon, 18 Oct 2021 12:35:20 +0000 (14:35 +0200)
committerMark Wielaard <mark@klomp.org>
Mon, 18 Oct 2021 12:35:33 +0000 (14:35 +0200)
commit c3a6a9dfc "libdw: Use signedness of subrange type to
determine array bounds" introduced a type check on a DIE which
exposed a latent bug in the get_type function. Even if the type
of a DIE couldn't be determined it would call dwarf_peel_type
on it. The gcc undefined sanitizer would flag this as being
undefined behaviour because the second argument of the function
is marked as non-NULL. Fix this by checking we actually have
a non-NULL type DIE.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdw/ChangeLog
libdw/dwarf_aggregate_size.c

index 4275b830f5ab856e23bd47bb74714f4f867d2e3b..311f34b5fb3b2e8242e292c2496042b6b8566949 100644 (file)
@@ -1,3 +1,8 @@
+2021-10-18  Mark Wielaard  <mark@klomp.org>
+
+       * dwarf_aggregate_size.c (get_type): Don't pass NULL to
+       dwarf_peel_type.
+
 2021-10-06  Mark Wielaard  <mark@klomp.org>
 
        * dwarf_aggregate_size.c (array_size): Check signedness of child DIE
index 96023d69db10fc6ff99de9f3bd3e45ba4979ce29..89f2029ed7418e02962e8a83f75883c1a41d27f0 100644 (file)
@@ -40,7 +40,7 @@ get_type (Dwarf_Die *die, Dwarf_Attribute *attr_mem, Dwarf_Die *type_mem)
   Dwarf_Die *type = INTUSE(dwarf_formref_die)
     (INTUSE(dwarf_attr_integrate) (die, DW_AT_type, attr_mem), type_mem);
 
-  if (INTUSE(dwarf_peel_type) (type, type) != 0)
+  if (type == NULL || INTUSE(dwarf_peel_type) (type, type) != 0)
     return NULL;
 
   return type;