This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] 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 <mjw@redhat.com>
---
 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  <mjw@redhat.com>
 
+	* strings.c (readelf): Use "<unknown>" if we cannot retrieve section
+	name.
+
+2015-06-18  Mark Wielaard  <mjw@redhat.com>
+
 	* readelf.c (handle_gnu_hash): Free lengths on invalid_data.
 
 2015-06-09  Mark Wielaard  <mjw@redhat.com>
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]