From: Mark Wielaard Date: Thu, 18 Jun 2015 09:00:51 +0000 (+0200) Subject: strings: Handle failure of getting section name on bogus section data. X-Git-Tag: elfutils-0.163~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=afd11605de0d2e16e8a2fa3094fa468b1901cd5e;p=thirdparty%2Felfutils.git strings: Handle failure of getting section name on bogus section data. 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 --- diff --git a/src/ChangeLog b/src/ChangeLog index 15e6faea9..3d7761f9d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2015-06-18 Mark Wielaard + + * strings.c (readelf): Use "" if we cannot retrieve section + name. + 2015-06-09 Mark Wielaard * addr2line.c (print_dwarf_function): Always free scopes before diff --git a/src/strings.c b/src/strings.c index b2bce7b43..88a3c2f8f 100644 --- a/src/strings.c +++ b/src/strings.c @@ -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 = ""; + else + sname = elf_strptr (elf, strndx, shdr->sh_name) ?: ""; 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