]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw: Always check __libdw_find_attr return value.
authorMark Wielaard <mjw@redhat.com>
Sun, 23 Nov 2014 22:21:05 +0000 (23:21 +0100)
committerMark Wielaard <mjw@redhat.com>
Wed, 26 Nov 2014 19:25:58 +0000 (20:25 +0100)
__libdw_find_attr will return NULL and might not set code or form.
Only use code or form if the returned address is not NULL.

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

index a3f204a7214dc2f2214279a4ce5a538c5c01d98d..19d6689cb04e3a0dae7d5b8cdcf7fe511529b55f 100644 (file)
@@ -1,3 +1,9 @@
+2014-11-23  Mark Wielaard  <mjw@redhat.com>
+
+       * dwarf_attr.c (dwarf_attr): Check __libdw_find_attr return value.
+       * dwarf_hasattr.c (dwarf_hasattr): Likewise.
+       * dwarf_siblingof.c (dwarf_siblingof): Likewise.
+
 2014-11-23  Mark Wielaard  <mjw@redhat.com>
 
        * dwarf_getabbrev.c (__libdw_getabbrev): Don't assert on bad DWARF.
index 97b08068648653be4574c53c59f33937d226f701..f247c1afe0ee0137182e2706418e99d56abe6896 100644 (file)
@@ -1,5 +1,5 @@
 /* Return specific DWARF attribute of a DIE.
-   Copyright (C) 2003, 2005 Red Hat, Inc.
+   Copyright (C) 2003, 2005, 2014 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2003.
 
@@ -50,6 +50,6 @@ dwarf_attr (die, search_name, result)
   /* Always fill in the CU information.  */
   result->cu = die->cu;
 
-  return result->code == search_name ? result : NULL;
+  return result->valp != NULL && result->code == search_name ? result : NULL;
 }
 INTDEF(dwarf_attr)
index 7933c1c3ff6db18de26b88519f9be1182833453b..fb7e1d5ed495110449c919710c15a56353a708fb 100644 (file)
@@ -1,5 +1,5 @@
 /* Check whether given DIE has specific attribute.
-   Copyright (C) 2003, 2005 Red Hat, Inc.
+   Copyright (C) 2003, 2005, 2014 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2003.
 
@@ -45,8 +45,8 @@ dwarf_hasattr (die, search_name)
 
   /* Search for the attribute with the given name.  */
   unsigned int code;
-  (void) __libdw_find_attr (die, search_name, &code, NULL);
+  unsigned char *addr = __libdw_find_attr (die, search_name, &code, NULL);
 
-  return code == search_name;
+  return addr != NULL && code == search_name;
 }
 INTDEF (dwarf_hasattr)
index c54b6c8db905c16a80f5276a49ca03cc28c69605..f2dc46888e9148042f83af278058228da90dbc3e 100644 (file)
@@ -1,5 +1,5 @@
 /* Return sibling of given DIE.
-   Copyright (C) 2003-2010 Red Hat, Inc.
+   Copyright (C) 2003-2010, 2014 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2003.
 
@@ -72,7 +72,7 @@ dwarf_siblingof (die, result)
       /* Find the end of the DIE or the sibling attribute.  */
       addr = __libdw_find_attr (&this_die, DW_AT_sibling, &sibattr.code,
                                &sibattr.form);
-      if (sibattr.code == DW_AT_sibling)
+      if (addr != NULL && sibattr.code == DW_AT_sibling)
        {
          Dwarf_Off offset;
          sibattr.valp = addr;