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: Produce error when section data falls outside file.


https://bugzilla.redhat.com/show_bug.cgi?id=1170810

Reported-by: Alexander Cherepanov <cherepan@mccme.ru>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 src/ChangeLog |  5 +++++
 src/strings.c | 17 +++++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 904b3c9..66d6270 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
 2014-12-26  Mark Wielaard  <mjw@redhat.com>
 
+	* strings.c (read_elf): Produce error when section data falls outside
+	file.
+
+2014-12-26  Mark Wielaard  <mjw@redhat.com>
+
 	* nm.c (show_symbols): Guard against divide by zero in error check.
 	Add section index number in error message.
 
diff --git a/src/strings.c b/src/strings.c
index f60e4b4..d1eb7b2 100644
--- a/src/strings.c
+++ b/src/strings.c
@@ -725,8 +725,21 @@ read_elf (Elf *elf, int fd, const char *fname, off64_t fdlen)
 	 actually have content.  */
       if (shdr != NULL && shdr->sh_type != SHT_NOBITS
 	  && (shdr->sh_flags & SHF_ALLOC) != 0)
-	result |= read_block (fd, fname, fdlen, shdr->sh_offset,
-			      shdr->sh_offset + shdr->sh_size);
+	{
+	  if (shdr->sh_offset > fdlen
+	      || fdlen - shdr->sh_offset < shdr->sh_size)
+	    {
+	      size_t strndx = 0;
+	      elf_getshdrstrndx (elf, &strndx);
+	      error (0, 0,
+		     gettext ("Skipping section %zd '%s' data outside file"),
+		     elf_ndxscn (scn), elf_strptr (elf, strndx, shdr->sh_name));
+	      result = 1;
+	    }
+	  else
+	    result |= read_block (fd, fname, fdlen, shdr->sh_offset,
+				  shdr->sh_offset + shdr->sh_size);
+	}
     }
   while ((scn = elf_nextscn (elf, scn)) != NULL);
 
-- 
2.1.0


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