From: Mark Wielaard Date: Sun, 1 Nov 2020 17:52:15 +0000 (+0100) Subject: libelf: Check header exists in elf_strptr X-Git-Tag: elfutils-0.183~98 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f31e45b1456b551ef8ee4711b06280a58954d980;p=thirdparty%2Felfutils.git libelf: Check header exists in elf_strptr 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 --- diff --git a/libelf/ChangeLog b/libelf/ChangeLog index aee1ffff5..db3eed082 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,7 @@ +2020-11-01 Mark Wielaard + + * elf_strptr.c (elf_strptr): Check shdr is not NULL. + 2020-11-01 Mark Wielaard * elf_getphdrnum.c (__elf_getphdrnum_rdlock): Set *dst to zero on diff --git a/libelf/elf_strptr.c b/libelf/elf_strptr.c index c72717074..76f2caf15 100644 --- a/libelf/elf_strptr.c +++ b/libelf/elf_strptr.c @@ -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);