public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libdw: Always check __libdw_find_attr return value.
@ 2014-11-23 23:21 Mark Wielaard
  0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2014-11-23 23:21 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 3166 bytes --]

__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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-11-23 23:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-23 23:21 [PATCH] libdw: Always check __libdw_find_attr return value Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).