From 1d5037f725b691929396896fd2b6be3cae1d87ef Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 6 Feb 2013 13:15:10 +0100 Subject: [PATCH] backends: Check type DIE exists before calling dwarf_tag (). 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 --- backends/ChangeLog | 17 +++++++++++++++++ backends/alpha_retval.c | 6 +++--- backends/arm_retval.c | 6 +++--- backends/i386_retval.c | 6 +++--- backends/ia64_retval.c | 8 ++++---- backends/libebl_CPU.h | 6 ++++++ backends/ppc64_retval.c | 8 ++++---- backends/ppc_retval.c | 6 +++--- backends/s390_retval.c | 6 +++--- backends/sh_retval.c | 6 +++--- backends/sparc_retval.c | 6 +++--- backends/tilegx_retval.c | 8 ++++---- backends/x86_64_retval.c | 6 +++--- 13 files changed, 59 insertions(+), 36 deletions(-) diff --git a/backends/ChangeLog b/backends/ChangeLog index ab9cde9c3..5fd3b6dbb 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,20 @@ +2013-02-06 Mark Wielaard + + * 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 Roland McGrath diff --git a/backends/alpha_retval.c b/backends/alpha_retval.c index 62cbfc7c7..6dfa69441 100644 --- a/backends/alpha_retval.c +++ b/backends/alpha_retval.c @@ -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. */ diff --git a/backends/arm_retval.c b/backends/arm_retval.c index 0c33c5b12..222f75553 100644 --- a/backends/arm_retval.c +++ b/backends/arm_retval.c @@ -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. */ diff --git a/backends/i386_retval.c b/backends/i386_retval.c index 95f5b9268..90678c325 100644 --- a/backends/i386_retval.c +++ b/backends/i386_retval.c @@ -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. */ diff --git a/backends/ia64_retval.c b/backends/ia64_retval.c index 644359b4d..ac0d8c3d3 100644 --- a/backends/ia64_retval.c +++ b/backends/ia64_retval.c @@ -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. */ diff --git a/backends/libebl_CPU.h b/backends/libebl_CPU.h index 36b3a4a13..09c8cd10b 100644 --- a/backends/libebl_CPU.h +++ b/backends/libebl_CPU.h @@ -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 */ diff --git a/backends/ppc64_retval.c b/backends/ppc64_retval.c index b26bb1ee1..c5c3b6fef 100644 --- a/backends/ppc64_retval.c +++ b/backends/ppc64_retval.c @@ -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, diff --git a/backends/ppc_retval.c b/backends/ppc_retval.c index 29f5a23d1..7ca0c1851 100644 --- a/backends/ppc_retval.c +++ b/backends/ppc_retval.c @@ -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. */ diff --git a/backends/s390_retval.c b/backends/s390_retval.c index 4cebe456d..b671ee86b 100644 --- a/backends/s390_retval.c +++ b/backends/s390_retval.c @@ -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. */ diff --git a/backends/sh_retval.c b/backends/sh_retval.c index 4692d35c8..116623184 100644 --- a/backends/sh_retval.c +++ b/backends/sh_retval.c @@ -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. */ diff --git a/backends/sparc_retval.c b/backends/sparc_retval.c index 2c2728c67..dcd378598 100644 --- a/backends/sparc_retval.c +++ b/backends/sparc_retval.c @@ -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. */ diff --git a/backends/tilegx_retval.c b/backends/tilegx_retval.c index fd4feef3a..e14cc5124 100644 --- a/backends/tilegx_retval.c +++ b/backends/tilegx_retval.c @@ -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, diff --git a/backends/x86_64_retval.c b/backends/x86_64_retval.c index d67b05f90..f3e9f2be2 100644 --- a/backends/x86_64_retval.c +++ b/backends/x86_64_retval.c @@ -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. */ -- 2.47.2