From 322709393b5881f4fc2fe1a03a00434edd8a5ce4 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 16 Dec 2014 22:19:08 +0100 Subject: [PATCH] readelf: Print dwarf_errmsg if dwarf_onesrcline or dwarf_linesrc fails. Don't just crash using the NULL result in print_decoded_line_section. Signed-off-by: Mark Wielaard --- src/ChangeLog | 5 +++++ src/readelf.c | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index 576ed83f0..7fc39b4a2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2014-12-16 Mark Wielaard + + * readelf.c (print_decoded_line_section): Print dwarf_errmsg if + dwarf_onesrcline or dwarf_linesrc fails. + 2014-12-16 Mark Wielaard * readelf.c (print_debug_line_section): Correct overflow check for diff --git a/src/readelf.c b/src/readelf.c index 9c62853e3..08b3ae477 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -6256,9 +6256,19 @@ print_decoded_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, for (size_t n = 0; n < nlines; n++) { Dwarf_Line *line = dwarf_onesrcline (lines, n); + if (line == NULL) + { + printf (" dwarf_onesrcline: %s\n", dwarf_errmsg (-1)); + continue; + } Dwarf_Word mtime, length; const char *file = dwarf_linesrc (line, &mtime, &length); - if (strcmp (last_file, file) != 0) + if (file == NULL) + { + printf (" <%s> (mtime: ?, length: ?)\n", dwarf_errmsg (-1)); + last_file = ""; + } + else if (strcmp (last_file, file) != 0) { printf (" %s (mtime: %" PRIu64 ", length: %" PRIu64 ")\n", file, mtime, length); -- 2.47.3