Don't just crash using the NULL result in print_decoded_line_section.

Signed-off-by: Mark Wielaard <[email protected]>
---
 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  <[email protected]>
 
+       * readelf.c (print_decoded_line_section): Print dwarf_errmsg if
+       dwarf_onesrcline or dwarf_linesrc fails.
+
+2014-12-16  Mark Wielaard  <[email protected]>
+
        * 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

Reply via email to