]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
backends: Check type DIE exists before calling dwarf_tag ().
authorMark Wielaard <mjw@redhat.com>
Wed, 6 Feb 2013 12:15:10 +0000 (13:15 +0100)
committerMark Wielaard <mjw@redhat.com>
Wed, 6 Feb 2013 22:27:03 +0000 (23:27 +0100)
dwarf_attr () or dwarf_form () functions leave typedie NULL when they fail
because of missing attribute or unexpected form. In such cases first check
the DIE exists and return error instead of calling dwarf_tag () and crashing.

This also happens in the testsuite with native tests when elfutils is build
without DWZ support on a distro that uses DWZ DWARF compression on system
libraries. Only the backends used dwarf_tag () directly without checking,
all other uses in elfutils already checked whether the given DIE was NULL.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
13 files changed:
backends/ChangeLog
backends/alpha_retval.c
backends/arm_retval.c
backends/i386_retval.c
backends/ia64_retval.c
backends/libebl_CPU.h
backends/ppc64_retval.c
backends/ppc_retval.c
backends/s390_retval.c
backends/sh_retval.c
backends/sparc_retval.c
backends/tilegx_retval.c
backends/x86_64_retval.c

index ab9cde9c3adc7a3bef45185575e359ca53e0235f..5fd3b6dbb5b64d3b8d01965a1c05b83786b4ac3d 100644 (file)
@@ -1,3 +1,20 @@
+2013-02-06  Mark Wielaard  <mjw@redhat.com>
+
+       * libebl_CPU.h (DWARF_TAG_OR_RETURN): New macro.
+       * backends/alpha_retval.c (alpha_return_value_location): Use new
+       DWARF_TAG_OR_RETURN macro instead of dwarf_tag ().
+       * backends/arm_retval.c (arm_return_value_location): Likewise.
+       * backends/i386_retval.c (i386_return_value_location): Likewise.
+       * backends/ia64_retval.c (hfa_type): Likewise.
+       (ia64_return_value_location): Likewise.
+       * backends/ppc64_retval.c (ppc64_return_value_location): Likewise.
+       * backends/ppc_retval.c (ppc_return_value_location): Likewise.
+       * backends/s390_retval.c (s390_return_value_location): Likewise.
+       * backends/sh_retval.c (sh_return_value_location): Likewise.
+       * backends/sparc_retval.c (sparc_return_value_location): Likewise.
+       * backends/tilegx_retval.c (tilegx_return_value_location): Likewise.
+       * backends/x86_64_retval.c (x86_64_return_value_location): Likewise.
+
 2013-01-29  Jan Kratochvil  <jan.kratochvil@redhat.com>
            Roland McGrath <roland@hack.frob.com>
 
index 62cbfc7c796504589604670cc8ab0622ec238dcd..6dfa6944176cb00de7b2a91cb765711ad524cf23 100644 (file)
@@ -77,7 +77,7 @@ alpha_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
 
   Dwarf_Die die_mem;
   Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
-  int tag = dwarf_tag (typedie);
+  int tag = DWARF_TAG_OR_RETURN (typedie);
 
   /* Follow typedefs and qualifiers to get to the actual type.  */
   while (tag == DW_TAG_typedef
@@ -86,7 +86,7 @@ alpha_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
     {
       attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
       typedie = dwarf_formref_die (attr, &die_mem);
-      tag = dwarf_tag (typedie);
+      tag = DWARF_TAG_OR_RETURN (typedie);
     }
 
   switch (tag)
@@ -99,7 +99,7 @@ alpha_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
        {
          attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
          typedie = dwarf_formref_die (attr, &die_mem);
-         tag = dwarf_tag (typedie);
+         tag = DWARF_TAG_OR_RETURN (typedie);
        }
       /* Fall through.  */
 
index 0c33c5b12b7aaa987d3b510a27877ada0c2ae4e2..222f75553323f9b5b0eaff0432221e3f333f53b4 100644 (file)
@@ -73,7 +73,7 @@ arm_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
 
   Dwarf_Die die_mem;
   Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
-  int tag = dwarf_tag (typedie);
+  int tag = DWARF_TAG_OR_RETURN (typedie);
 
   /* Follow typedefs and qualifiers to get to the actual type.  */
   while (tag == DW_TAG_typedef
@@ -82,7 +82,7 @@ arm_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
     {
       attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
       typedie = dwarf_formref_die (attr, &die_mem);
-      tag = dwarf_tag (typedie);
+      tag = DWARF_TAG_OR_RETURN (typedie);
     }
 
   Dwarf_Word size;
@@ -96,7 +96,7 @@ arm_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
        {
          attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
          typedie = dwarf_formref_die (attr, &die_mem);
-         tag = dwarf_tag (typedie);
+         tag = DWARF_TAG_OR_RETURN (typedie);
        }
       /* Fall through.  */
 
index 95f5b92683ecf2f2855a24be6e3fbcf754267cb3..90678c3256956453bc325dc1c413a9a373404a4a 100644 (file)
@@ -77,7 +77,7 @@ i386_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
 
   Dwarf_Die die_mem;
   Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
-  int tag = dwarf_tag (typedie);
+  int tag = DWARF_TAG_OR_RETURN (typedie);
 
   /* Follow typedefs and qualifiers to get to the actual type.  */
   while (tag == DW_TAG_typedef
@@ -86,7 +86,7 @@ i386_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
     {
       attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
       typedie = dwarf_formref_die (attr, &die_mem);
-      tag = dwarf_tag (typedie);
+      tag = DWARF_TAG_OR_RETURN (typedie);
     }
 
   switch (tag)
@@ -99,7 +99,7 @@ i386_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
        {
          attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
          typedie = dwarf_formref_die (attr, &die_mem);
-         tag = dwarf_tag (typedie);
+         tag = DWARF_TAG_OR_RETURN (typedie);
        }
       /* Fall through.  */
 
index 644359b4dc898ccfe46dc1a9de3c9119ecdbcaf6..ac0d8c3d3c4ec7e064ca5c7b8fd77d6467999c8b 100644 (file)
@@ -109,7 +109,7 @@ hfa_type (Dwarf_Die *typedie, Dwarf_Word size,
       return fpregs_used + nregs;
     }
 
-  int tag = dwarf_tag (typedie);
+  int tag = DWARF_TAG_OR_RETURN (typedie);
   switch (tag)
     {
       Dwarf_Attribute attr_mem;
@@ -248,7 +248,7 @@ ia64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
 
   Dwarf_Die die_mem;
   Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
-  int tag = dwarf_tag (typedie);
+  int tag = DWARF_TAG_OR_RETURN (typedie);
 
   /* Follow typedefs and qualifiers to get to the actual type.  */
   while (tag == DW_TAG_typedef
@@ -257,7 +257,7 @@ ia64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
     {
       attr = dwarf_attr (typedie, DW_AT_type, &attr_mem);
       typedie = dwarf_formref_die (attr, &die_mem);
-      tag = dwarf_tag (typedie);
+      tag = DWARF_TAG_OR_RETURN (typedie);
     }
 
   Dwarf_Word size;
@@ -271,7 +271,7 @@ ia64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
        {
          attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
          typedie = dwarf_formref_die (attr, &die_mem);
-         tag = dwarf_tag (typedie);
+         tag = DWARF_TAG_OR_RETURN (typedie);
        }
       /* Fall through.  */
 
index 36b3a4a135b7027a1d048e7e619b63e8ebee368b..09c8cd10b3c058446a712fa1cc22835010ea5b63 100644 (file)
@@ -45,5 +45,11 @@ extern const char *EBLHOOK(init) (Elf *elf, GElf_Half machine,
 
 extern bool (*generic_debugscn_p) (const char *) attribute_hidden;
 
+/* Helper for retval.  Return dwarf_tag (die), but calls return -1
+   if there where previous errors that leave die NULL.  */
+#define DWARF_TAG_OR_RETURN(die)  \
+  ({ Dwarf_Die *_die = (die);    \
+     if (_die == NULL) return -1; \
+     dwarf_tag (_die); })
 
 #endif /* libebl_CPU.h */
index b26bb1ee1b84af5098e9a0629ea898eccaad2a2d..c5c3b6fef45912c58076b8058e0cb1b3105a2f58 100644 (file)
@@ -87,7 +87,7 @@ ppc64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
 
   Dwarf_Die die_mem;
   Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
-  int tag = dwarf_tag (typedie);
+  int tag = DWARF_TAG_OR_RETURN (typedie);
 
   /* Follow typedefs and qualifiers to get to the actual type.  */
   while (tag == DW_TAG_typedef
@@ -96,7 +96,7 @@ ppc64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
     {
       attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
       typedie = dwarf_formref_die (attr, &die_mem);
-      tag = dwarf_tag (typedie);
+      tag = DWARF_TAG_OR_RETURN (typedie);
     }
 
   Dwarf_Word size;
@@ -110,7 +110,7 @@ ppc64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
        {
          attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
          typedie = dwarf_formref_die (attr, &die_mem);
-         tag = dwarf_tag (typedie);
+         tag = DWARF_TAG_OR_RETURN (typedie);
        }
       /* Fall through.  */
 
@@ -181,7 +181,7 @@ ppc64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
              /* Check if it's a character array.  */
              attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
              typedie = dwarf_formref_die (attr, &die_mem);
-             tag = dwarf_tag (typedie);
+             tag = DWARF_TAG_OR_RETURN (typedie);
              if (tag != DW_TAG_base_type)
                goto aggregate;
              if (dwarf_formudata (dwarf_attr_integrate (typedie,
index 29f5a23d1b61c0223ffcc988595a3b38c48e03dc..7ca0c18516d820f56f1c20151ba007cdafefd426 100644 (file)
@@ -99,7 +99,7 @@ ppc_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
 
   Dwarf_Die die_mem;
   Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
-  int tag = dwarf_tag (typedie);
+  int tag = DWARF_TAG_OR_RETURN (typedie);
 
   /* Follow typedefs and qualifiers to get to the actual type.  */
   while (tag == DW_TAG_typedef
@@ -108,7 +108,7 @@ ppc_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
     {
       attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
       typedie = dwarf_formref_die (attr, &die_mem);
-      tag = dwarf_tag (typedie);
+      tag = DWARF_TAG_OR_RETURN (typedie);
     }
 
   Dwarf_Word size;
@@ -122,7 +122,7 @@ ppc_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
        {
          attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
          typedie = dwarf_formref_die (attr, &die_mem);
-         tag = dwarf_tag (typedie);
+         tag = DWARF_TAG_OR_RETURN (typedie);
        }
       /* Fall through.  */
 
index 4cebe456d9d4444a0e036f381c258fff36ec47d6..b671ee86b04462c4ee070582a52871a54d0680b5 100644 (file)
@@ -78,7 +78,7 @@ s390_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
 
   Dwarf_Die die_mem;
   Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
-  int tag = dwarf_tag (typedie);
+  int tag = DWARF_TAG_OR_RETURN (typedie);
 
   /* Follow typedefs and qualifiers to get to the actual type.  */
   while (tag == DW_TAG_typedef
@@ -87,7 +87,7 @@ s390_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
     {
       attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
       typedie = dwarf_formref_die (attr, &die_mem);
-      tag = dwarf_tag (typedie);
+      tag = DWARF_TAG_OR_RETURN (typedie);
     }
 
   Dwarf_Word size;
@@ -101,7 +101,7 @@ s390_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
        {
          attr = dwarf_attr (typedie, DW_AT_type, &attr_mem);
          typedie = dwarf_formref_die (attr, &die_mem);
-         tag = dwarf_tag (typedie);
+         tag = DWARF_TAG_OR_RETURN (typedie);
        }
       /* Fall through.  */
 
index 4692d35c81fa1f93dced23b4ca06790eddbd2a2a..1166231845182875269d96d70af5a93e28a771d6 100644 (file)
@@ -75,7 +75,7 @@ sh_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
 
   Dwarf_Die die_mem;
   Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
-  int tag = dwarf_tag (typedie);
+  int tag = DWARF_TAG_OR_RETURN (typedie);
 
   /* Follow typedefs and qualifiers to get to the actual type.  */
   while (tag == DW_TAG_typedef
@@ -84,7 +84,7 @@ sh_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
     {
       attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
       typedie = dwarf_formref_die (attr, &die_mem);
-      tag = dwarf_tag (typedie);
+      tag = DWARF_TAG_OR_RETURN (typedie);
     }
 
   Dwarf_Word size;
@@ -98,7 +98,7 @@ sh_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
        {
          attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
          typedie = dwarf_formref_die (attr, &die_mem);
-         tag = dwarf_tag (typedie);
+         tag = DWARF_TAG_OR_RETURN (typedie);
        }
       /* Fall through.  */
 
index 2c2728c671833d9c0ba4391ef57da98a28a61ae4..dcd378598f872fe9dae685db82bd61550d04b7f1 100644 (file)
@@ -82,7 +82,7 @@ sparc_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
 
   Dwarf_Die die_mem;
   Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
-  int tag = dwarf_tag (typedie);
+  int tag = DWARF_TAG_OR_RETURN (typedie);
 
   /* Follow typedefs and qualifiers to get to the actual type.  */
   while (tag == DW_TAG_typedef
@@ -91,7 +91,7 @@ sparc_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
     {
       attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
       typedie = dwarf_formref_die (attr, &die_mem);
-      tag = dwarf_tag (typedie);
+      tag = DWARF_TAG_OR_RETURN (typedie);
     }
 
   Dwarf_Word size;
@@ -105,7 +105,7 @@ sparc_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
        {
          attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
          typedie = dwarf_formref_die (attr, &die_mem);
-         tag = dwarf_tag (typedie);
+         tag = DWARF_TAG_OR_RETURN (typedie);
        }
       /* Fall through.  */
 
index fd4feef3ab50bca3a7234cb7ce2470dd5979ceb1..e14cc51243594c3d7900117caa7d1b9d6a9b9e7d 100644 (file)
@@ -69,7 +69,7 @@ tilegx_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
 
   Dwarf_Die die_mem;
   Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
-  int tag = dwarf_tag (typedie);
+  int tag = DWARF_TAG_OR_RETURN (typedie);
 
   /* Follow typedefs and qualifiers to get to the actual type.  */
   while (tag == DW_TAG_typedef
@@ -78,7 +78,7 @@ tilegx_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
     {
       attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
       typedie = dwarf_formref_die (attr, &die_mem);
-      tag = dwarf_tag (typedie);
+      tag = DWARF_TAG_OR_RETURN (typedie);
     }
 
   Dwarf_Word size;
@@ -92,7 +92,7 @@ tilegx_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
        {
          attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
          typedie = dwarf_formref_die (attr, &die_mem);
-         tag = dwarf_tag (typedie);
+         tag = DWARF_TAG_OR_RETURN (typedie);
        }
       /* Fall through.  */
 
@@ -142,7 +142,7 @@ tilegx_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
              /* Check if it's a character array.  */
              attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
              typedie = dwarf_formref_die (attr, &die_mem);
-             tag = dwarf_tag (typedie);
+             tag = DWARF_TAG_OR_RETURN (typedie);
              if (tag != DW_TAG_base_type)
                goto aggregate;
              if (dwarf_formudata (dwarf_attr_integrate (typedie,
index d67b05f90b8dfb37dcac4965e09624935aa64458..f3e9f2be29936473c738bd19e81f003155106db2 100644 (file)
@@ -91,7 +91,7 @@ x86_64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
 
   Dwarf_Die die_mem;
   Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
-  int tag = dwarf_tag (typedie);
+  int tag = DWARF_TAG_OR_RETURN (typedie);
 
   /* Follow typedefs and qualifiers to get to the actual type.  */
   while (tag == DW_TAG_typedef
@@ -100,7 +100,7 @@ x86_64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
     {
       attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
       typedie = dwarf_formref_die (attr, &die_mem);
-      tag = dwarf_tag (typedie);
+      tag = DWARF_TAG_OR_RETURN (typedie);
     }
 
   Dwarf_Word size;
@@ -114,7 +114,7 @@ x86_64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
        {
          attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
          typedie = dwarf_formref_die (attr, &die_mem);
-         tag = dwarf_tag (typedie);
+         tag = DWARF_TAG_OR_RETURN (typedie);
        }
       /* Fall through.  */