]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: Check header exists in elf_strptr
authorMark Wielaard <mark@klomp.org>
Sun, 1 Nov 2020 17:52:15 +0000 (18:52 +0100)
committerMark Wielaard <mark@klomp.org>
Fri, 6 Nov 2020 17:39:40 +0000 (18:39 +0100)
We already checked the header actually existed for ELFCLASS64 but not
for the ELFCLASS32 case. It is very unlikely it is at this point in the
code, but theoretically it could happen.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libelf/ChangeLog
libelf/elf_strptr.c

index aee1ffff55337575b0059e92a9a73f35eb7eb2a1..db3eed0822f190c3817b3bb406d95ddd87d36f4c 100644 (file)
@@ -1,3 +1,7 @@
+2020-11-01  Mark Wielaard  <mark@klomp.org>
+
+       * elf_strptr.c (elf_strptr): Check shdr is not NULL.
+
 2020-11-01  Mark Wielaard  <mark@klomp.org>
 
        * elf_getphdrnum.c (__elf_getphdrnum_rdlock): Set *dst to zero on
index c727170748208aa0b9bdd8ddb31d58cb4bb27914..76f2caf15747eb551018f034eb957b83ed535926 100644 (file)
@@ -119,7 +119,7 @@ elf_strptr (Elf *elf, size_t idx, size_t offset)
   if (elf->class == ELFCLASS32)
     {
       Elf32_Shdr *shdr = strscn->shdr.e32 ?: __elf32_getshdr_rdlock (strscn);
-      if (unlikely (shdr->sh_type != SHT_STRTAB))
+      if (unlikely (shdr == NULL || shdr->sh_type != SHT_STRTAB))
        {
          /* This is no string section.  */
          __libelf_seterrno (ELF_E_INVALID_SECTION);