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]> --- src/ChangeLog | 5 +++++ src/strings.c | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b548851..7c47079 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ 2015-06-18 Mark Wielaard <[email protected]> + * strings.c (readelf): Use "<unknown>" if we cannot retrieve section + name. + +2015-06-18 Mark Wielaard <[email protected]> + * readelf.c (handle_gnu_hash): Free lengths on invalid_data. 2015-06-09 Mark Wielaard <[email protected]> diff --git a/src/strings.c b/src/strings.c index b2bce7b..88a3c2f 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 -- 1.8.3.1
