]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
strings: Handle failure of getting section name on bogus section data.
authorMark Wielaard <mjw@redhat.com>
Thu, 18 Jun 2015 09:00:51 +0000 (11:00 +0200)
committerMark Wielaard <mjw@redhat.com>
Fri, 19 Jun 2015 10:29:46 +0000 (12:29 +0200)
If there is something wrong with getting the section data it is likely
we won't be able to get the actual section name because the file is
somehow corrupted. Try to get the name, but handle failure gracefully.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
src/ChangeLog
src/strings.c

index 15e6faea9cc30357581f84246dd9c274860f2ac5..3d7761f9da84e5241da0ac86d15aa446b30be240 100644 (file)
@@ -1,3 +1,8 @@
+2015-06-18  Mark Wielaard  <mjw@redhat.com>
+
+       * strings.c (readelf): Use "<unknown>" if we cannot retrieve section
+       name.
+
 2015-06-09  Mark Wielaard  <mjw@redhat.com>
 
        * addr2line.c (print_dwarf_function): Always free scopes before
index b2bce7b438ab575f4cda65a2b2898b1ba5dacf9c..88a3c2f8f7a80155b31d261d47bc3a1dcf7246d8 100644 (file)
@@ -730,10 +730,14 @@ read_elf (Elf *elf, int fd, const char *fname, off64_t fdlen)
              || fdlen - shdr->sh_offset < shdr->sh_size)
            {
              size_t strndx = 0;
-             elf_getshdrstrndx (elf, &strndx);
+             const char *sname;
+             if (unlikely (elf_getshdrstrndx (elf, &strndx) < 0))
+               sname = "<unknown>";
+             else
+               sname = elf_strptr (elf, strndx, shdr->sh_name) ?: "<unknown>";
              error (0, 0,
                     gettext ("Skipping section %zd '%s' data outside file"),
-                    elf_ndxscn (scn), elf_strptr (elf, strndx, shdr->sh_name));
+                    elf_ndxscn (scn), sname);
              result = 1;
            }
          else