]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: elf_getshdrstrndx cannot use SHN_XINDEX without section headers.
authorMark Wielaard <mjw@redhat.com>
Sun, 16 Nov 2014 23:42:53 +0000 (00:42 +0100)
committerMark Wielaard <mjw@redhat.com>
Sun, 16 Nov 2014 23:42:53 +0000 (00:42 +0100)
Signed-off-by: Mark Wielaard <mjw@redhat.com>
libelf/ChangeLog
libelf/elf_getshdrstrndx.c

index ef5da43d470d0eece203811291977be0147d0112..633a8923f8529e891b187f6db7340df7073b8630 100644 (file)
@@ -1,3 +1,8 @@
+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.
index 1dbed4c84616edb1677ece141a66b9a7367f76e3..6f8d66e8065210b027a91fb05ecf2d5a3ce64b33 100644 (file)
@@ -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;