This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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 <mjw@redhat.com>
---
 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 a81c339..2241c70 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 97b0806..f247c1a 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 7933c1c..fb7e1d5 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 c54b6c8..f2dc468 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;
-- 
1.9.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]