]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Do not reject type units in dwarf_getsrcfiles and dwarf_getsrclines
authorPetr Machata <pmachata@redhat.com>
Wed, 1 Apr 2015 19:44:32 +0000 (21:44 +0200)
committerPetr Machata <pmachata@redhat.com>
Fri, 3 Apr 2015 11:21:09 +0000 (13:21 +0200)
Signed-off-by: Petr Machata <pmachata@redhat.com>
libdw/ChangeLog
libdw/dwarf_error.c
libdw/dwarf_getsrcfiles.c
libdw/dwarf_getsrclines.c
libdw/libdwP.h

index 3ca85cbedf9885e8d0864ec659be1bc4b38c0ae3..3abb38283922779563471412461c05d996e9ef65 100644 (file)
@@ -1,3 +1,12 @@
+2015-04-01  Petr Machata  <pmachata@redhat.com>
+
+       * libdwP.h (DWARF_E_NOT_CUDIE): New enumerator.
+       (is_cudie): New function.
+       * dwarf_error.c (errmsgs): Add message for DWARF_E_NOT_CUDIE.
+       * dwarf_getsrcfiles.c (dwarf_getsrcfiles): Call is_cudie instead
+       of white-listing valid tags.
+       * dwarf_getsrclines.c (dwarf_getsrclines): Likewise.
+
 2015-03-18  Petr Machata  <pmachata@redhat.com>
 
        * Makefile.am (pkginclude_HEADERS): Add known-dwarf.h.
index 08b691aac5fe8b3d9390bd8ec1652a304254a849..aa97a68eb9d1ac7557ae8f09a1f3ab0f5a4882b0 100644 (file)
@@ -1,5 +1,5 @@
 /* Retrieve ELF descriptor used for DWARF access.
-   Copyright (C) 2002, 2003, 2004, 2005, 2009, 2014 Red Hat, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005, 2009, 2014, 2015 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -93,6 +93,7 @@ static const char *errmsgs[] =
     [DWARF_E_INVALID_CFI] = N_("invalid CFI section"),
     [DWARF_E_NO_ALT_DEBUGLINK] = N_("no alternative debug link found"),
     [DWARF_E_INVALID_OPCODE] = N_("invalid opcode"),
+    [DWARF_E_NOT_CUDIE] = N_("not a CU (unit) DIE"),
   };
 #define nerrmsgs (sizeof (errmsgs) / sizeof (errmsgs[0]))
 
index 4bfc34b8b48031e5e81978565d9a979a78a5856f..5af6f68bbdfe5b934e5c41fdd15e114dc3d07966 100644 (file)
@@ -1,5 +1,5 @@
 /* Return source file information of CU.
-   Copyright (C) 2004, 2005, 2013 Red Hat, Inc.
+   Copyright (C) 2004, 2005, 2013, 2015 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2004.
 
 int
 dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files, size_t *nfiles)
 {
-  if (unlikely (cudie == NULL
-               || (INTUSE(dwarf_tag) (cudie) != DW_TAG_compile_unit
-                   && INTUSE(dwarf_tag) (cudie) != DW_TAG_partial_unit)))
+  if (cudie == NULL)
     return -1;
+  if (! is_cudie (cudie))
+    {
+      __libdw_seterrno (DWARF_E_NOT_CUDIE);
+      return -1;
+    }
 
   int res = -1;
 
index 053b30f2f0a5874d547d18a4f941c0c178e6f99f..368f2fd8385c8e76cdbf4c8180ad88ef96111fc1 100644 (file)
@@ -1,5 +1,5 @@
 /* Return line number information of CU.
-   Copyright (C) 2004-2010, 2013, 2014 Red Hat, Inc.
+   Copyright (C) 2004-2010, 2013, 2014, 2015 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2004.
 
@@ -838,10 +838,13 @@ __libdw_getcompdir (Dwarf_Die *cudie)
 int
 dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines, size_t *nlines)
 {
-  if (unlikely (cudie == NULL
-               || (INTUSE(dwarf_tag) (cudie) != DW_TAG_compile_unit
-                   && INTUSE(dwarf_tag) (cudie) != DW_TAG_partial_unit)))
+  if (cudie == NULL)
     return -1;
+  if (! is_cudie (cudie))
+    {
+      __libdw_seterrno (DWARF_E_NOT_CUDIE);
+      return -1;
+    }
 
   /* Get the information if it is not already known.  */
   struct Dwarf_CU *const cu = cudie->cu;
index e38e0c9bbc73427e728f6e8b021a6dbf3f034dcf..fc7796016112d44c93117b6d68c031c41cdf5121 100644 (file)
@@ -128,6 +128,7 @@ enum
   DWARF_E_INVALID_CFI,
   DWARF_E_NO_ALT_DEBUGLINK,
   DWARF_E_INVALID_OPCODE,
+  DWARF_E_NOT_CUDIE,
 };
 
 
@@ -725,6 +726,12 @@ cu_sec_idx (struct Dwarf_CU *cu)
   return cu->type_offset == 0 ? IDX_debug_info : IDX_debug_types;
 }
 
+static inline bool
+is_cudie (Dwarf_Die *cudie)
+{
+  return CUDIE (cudie->cu).addr == cudie->addr;
+}
+
 /* Read up begin/end pair and increment read pointer.
     - If it's normal range record, set up *BEGINP and *ENDP and return 0.
     - If it's base address selection record, set up *BASEP and return 1.