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]

[COMMITTED] libelf: elf_getshdrstrndx cannot use SHN_XINDEX without section headers.


Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 libelf/ChangeLog           |  5 +++++
 libelf/elf_getshdrstrndx.c | 15 +++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index ef5da43..633a892 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,5 +1,10 @@
 2014-11-16  Mark Wielaard  <mjw@redhat.com>
 
+	* elf_getshdrstrndx.c: Check there are section headers before
+	handling SHN_XINDEX.
+
+2014-11-16  Mark Wielaard  <mjw@redhat.com>
+
 	* elf32_getphdr.c (getphdr_wrlock): Check e_phoff isn't zero.
 	Check for too many pheaders.
 	* elf_getphdrnum.c (__elf_getphdrnum_rdlock): Check section zero
diff --git a/libelf/elf_getshdrstrndx.c b/libelf/elf_getshdrstrndx.c
index 1dbed4c..6f8d66e 100644
--- a/libelf/elf_getshdrstrndx.c
+++ b/libelf/elf_getshdrstrndx.c
@@ -92,6 +92,13 @@ elf_getshdrstrndx (elf, dst)
 	  if (elf->class == ELFCLASS32)
 	    {
 	      size_t offset;
+	      if (unlikely (elf->state.elf32.scns.cnt == 0))
+		{
+		  /* Cannot use SHN_XINDEX without section headers.  */
+		  __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
+		  result = -1;
+		  goto out;
+		}
 
 	      if (elf->state.elf32.scns.data[0].shdr.e32 != NULL)
 		{
@@ -146,6 +153,14 @@ elf_getshdrstrndx (elf, dst)
 	    }
 	  else
 	    {
+	      if (unlikely (elf->state.elf64.scns.cnt == 0))
+		{
+		  /* Cannot use SHN_XINDEX without section headers.  */
+		  __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
+		  result = -1;
+		  goto out;
+		}
+
 	      if (elf->state.elf64.scns.data[0].shdr.e64 != NULL)
 		{
 		  num = elf->state.elf64.scns.data[0].shdr.e64->sh_link;
-- 
1.8.3.1


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