public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [COMMITTED] libelf: elf_getshdrstrndx cannot use SHN_XINDEX without section headers.
@ 2014-11-16 23:43 Mark Wielaard
  0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2014-11-16 23:43 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 1702 bytes --]

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-11-16 23:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-16 23:43 [COMMITTED] libelf: elf_getshdrstrndx cannot use SHN_XINDEX without section headers Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).