diff options
author | Mark Wielaard <[email protected]> | 2015-06-18 11:00:51 +0200 |
---|---|---|
committer | Mark Wielaard <[email protected]> | 2015-06-19 12:29:46 +0200 |
commit | afd11605de0d2e16e8a2fa3094fa468b1901cd5e (patch) | |
tree | bae7bacc2f4ec013cd46c56ddb09e4a2631b30a5 | |
parent | aec69c7f2adcf9674f025c7f79cbeabbbd4e6b6a (diff) |
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 <[email protected]>
-rw-r--r-- | src/ChangeLog | 5 | ||||
-rw-r--r-- | src/strings.c | 8 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 15e6faea..3d7761f9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2015-06-18 Mark Wielaard <[email protected]> + + * strings.c (readelf): Use "<unknown>" if we cannot retrieve section + name. + 2015-06-09 Mark Wielaard <[email protected]> * addr2line.c (print_dwarf_function): Always free scopes before diff --git a/src/strings.c b/src/strings.c index b2bce7b4..88a3c2f8 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 = "<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 |