* [PATCH] readelf: Print dwarf_errmsg if dwarf_onesrcline or dwarf_linesrc fails.
@ 2014-12-16 21:20 Mark Wielaard
0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2014-12-16 21:20 UTC (permalink / raw)
To: elfutils-devel
[-- Attachment #1: Type: text/plain, Size: 1626 bytes --]
Don't just crash using the NULL result in print_decoded_line_section.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
src/ChangeLog | 5 +++++
src/readelf.c | 12 +++++++++++-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/ChangeLog b/src/ChangeLog
index 7960496..9d14db0 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
2014-12-16 Mark Wielaard <mjw@redhat.com>
+ * readelf.c (print_decoded_line_section): Print dwarf_errmsg if
+ dwarf_onesrcline or dwarf_linesrc fails.
+
+2014-12-16 Mark Wielaard <mjw@redhat.com>
+
* readelf.c (print_debug_line_section): Correct overflow check for
unit_length.
(print_debug_aranges_section): Correct overflow check for length.
diff --git a/src/readelf.c b/src/readelf.c
index 9c62853..08b3ae4 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.1.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-12-16 21:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-16 21:20 [PATCH] readelf: Print dwarf_errmsg if dwarf_onesrcline or dwarf_linesrc fails Mark Wielaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).