summaryrefslogtreecommitdiffstats
path: root/backends/libebl_CPU.h
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2013-02-06 13:15:10 +0100
committerMark Wielaard <[email protected]>2013-02-06 23:27:03 +0100
commit1d5037f725b691929396896fd2b6be3cae1d87ef (patch)
treeefa4f61691eb0d74b6dae5ceb4b3901282420741 /backends/libebl_CPU.h
parent6c4b2078c51c687a1a192b001f0b331a0ccac629 (diff)
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 <[email protected]>
Diffstat (limited to 'backends/libebl_CPU.h')
-rw-r--r--backends/libebl_CPU.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/backends/libebl_CPU.h b/backends/libebl_CPU.h
index 36b3a4a1..09c8cd10 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 */