From 59480ba86fdaad7eb2e104b69af4a3b07e20d6fb Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sun, 23 Nov 2014 23:21:05 +0100 Subject: [PATCH] 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 --- libdw/ChangeLog | 6 ++++++ libdw/dwarf_attr.c | 4 ++-- libdw/dwarf_hasattr.c | 6 +++--- libdw/dwarf_siblingof.c | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index a3f204a72..19d6689cb 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,9 @@ +2014-11-23 Mark Wielaard + + * 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 * dwarf_getabbrev.c (__libdw_getabbrev): Don't assert on bad DWARF. diff --git a/libdw/dwarf_attr.c b/libdw/dwarf_attr.c index 97b080686..f247c1afe 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 , 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 7933c1c3f..fb7e1d5ed 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 , 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 c54b6c8db..f2dc46888 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 , 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; -- 2.47.3