summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2014-11-23 23:21:05 +0100
committerMark Wielaard <mjw@redhat.com>2014-11-26 20:25:58 +0100
commit59480ba86fdaad7eb2e104b69af4a3b07e20d6fb (patch)
treef5732c386943641cb75f705fcc1e0563457cd8b8
parent04b61f8601bf9267976cc4461091622ffdbadf67 (diff)
downloadandroid_external_elfutils-59480ba86fdaad7eb2e104b69af4a3b07e20d6fb.tar.gz
android_external_elfutils-59480ba86fdaad7eb2e104b69af4a3b07e20d6fb.tar.bz2
android_external_elfutils-59480ba86fdaad7eb2e104b69af4a3b07e20d6fb.zip
libdw: Always check __libdw_find_attr return value.
__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>
-rw-r--r--libdw/ChangeLog6
-rw-r--r--libdw/dwarf_attr.c4
-rw-r--r--libdw/dwarf_hasattr.c6
-rw-r--r--libdw/dwarf_siblingof.c4
4 files changed, 13 insertions, 7 deletions
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index a3f204a7..19d6689c 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,11 @@
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.
Set libdw errno and return NULL.
diff --git a/libdw/dwarf_attr.c b/libdw/dwarf_attr.c
index 97b08068..f247c1af 100644
--- a/libdw/dwarf_attr.c
+++ b/libdw/dwarf_attr.c
@@ -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)
diff --git a/libdw/dwarf_hasattr.c b/libdw/dwarf_hasattr.c
index 7933c1c3..fb7e1d5e 100644
--- a/libdw/dwarf_hasattr.c
+++ b/libdw/dwarf_hasattr.c
@@ -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)
diff --git a/libdw/dwarf_siblingof.c b/libdw/dwarf_siblingof.c
index c54b6c8d..f2dc4688 100644
--- a/libdw/dwarf_siblingof.c
+++ b/libdw/dwarf_siblingof.c
@@ -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;