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: Read DW_AT_decl_file/line/column as unsigned


Section 2.14 of the DWARF v3 & v4 standards specifies that all three
declaration coordinates are unsigned integer constants.  DWARF v2 did
not specify signedness.  Now dwarf_decl_* use dwarf_formudata to read
these values.

Also, an assertion on the range of line/column is now a handled error,
setting DWARF_E_INVALID_DWARF for values greater than INT_MAX.

Signed-off-by: Josh Stone <jistone@redhat.com>
---
 libdw/ChangeLog         |  6 ++++++
 libdw/dwarf_decl_file.c |  4 ++--
 libdw/dwarf_decl_line.c | 13 +++++++++----
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 6e779c8e3cb7..19a2a505cdef 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,9 @@
+2014-02-05  Josh Stone  <jistone@redhat.com>
+
+	* dwarf_decl_file.c (dwarf_decl_file): Read the idx as unsigned.
+	* dwarf_decl_line.c (__libdw_attr_intval): Read the line/column as
+	unsigned.  Change the range assert to DWARF_E_INVALID_DWARF.
+
 2013-12-30  Mark Wielaard  <mjw@redhat.com>
 
 	* libdw.map (ELFUTILS_0.158): Add dwfl_core_file_attach and
diff --git a/libdw/dwarf_decl_file.c b/libdw/dwarf_decl_file.c
index c18aceb389f0..5657132f4eed 100644
--- a/libdw/dwarf_decl_file.c
+++ b/libdw/dwarf_decl_file.c
@@ -40,9 +40,9 @@ const char *
 dwarf_decl_file (Dwarf_Die *die)
 {
   Dwarf_Attribute attr_mem;
-  Dwarf_Sword idx = 0;
+  Dwarf_Word idx = 0;
 
-  if (INTUSE(dwarf_formsdata) (INTUSE(dwarf_attr_integrate)
+  if (INTUSE(dwarf_formudata) (INTUSE(dwarf_attr_integrate)
 			       (die, DW_AT_decl_file, &attr_mem),
 			       &idx) != 0)
     return NULL;
diff --git a/libdw/dwarf_decl_line.c b/libdw/dwarf_decl_line.c
index 5b6db5f5cd11..80fae6c90017 100644
--- a/libdw/dwarf_decl_line.c
+++ b/libdw/dwarf_decl_line.c
@@ -50,15 +50,20 @@ int internal_function
 __libdw_attr_intval (Dwarf_Die *die, int *linep, int attval)
 {
   Dwarf_Attribute attr_mem;
-  Dwarf_Sword line;
+  Dwarf_Word line;
 
-  int res = INTUSE(dwarf_formsdata) (INTUSE(dwarf_attr_integrate)
+  int res = INTUSE(dwarf_formudata) (INTUSE(dwarf_attr_integrate)
 				     (die, attval, &attr_mem),
 				     &line);
   if (res == 0)
     {
-      assert (line >= 0 && line <= INT_MAX);
-      *linep = line;
+      if (line > INT_MAX)
+	{
+	  __libdw_seterrno (DWARF_E_INVALID_DWARF);
+	  res = -1;
+	}
+      else
+	*linep = line;
     }
 
   return res;
-- 
1.8.5.3


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