From: Mark Wielaard Date: Sat, 9 May 2020 03:02:25 +0000 (+0200) Subject: libelf: Check for NULL shdr in elf_strptr. X-Git-Tag: elfutils-0.180~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24d6569408c2039a97054f3e6999cb174c076242;p=thirdparty%2Felfutils.git libelf: Check for NULL shdr in elf_strptr. GCC10 -fanalyzer with -flto notices __elf64_getshdr_rdlock can fail and because the result isn't checked in elf_strptr it can cause a dereference of NULL. Signed-off-by: Mark Wielaard --- diff --git a/libelf/ChangeLog b/libelf/ChangeLog index fcea8aa90..fd5518dc4 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,7 @@ +2020-05-08 Mark Wielaard + + * elf_strptr.c (elf_strptr): Check shdr is not NULL. + 2020-05-08 Mark Wielaard * elf_getdata.c (__libelf_set_rawdata_wrlock): Check diff --git a/libelf/elf_strptr.c b/libelf/elf_strptr.c index e72a3a369..c72717074 100644 --- a/libelf/elf_strptr.c +++ b/libelf/elf_strptr.c @@ -145,7 +145,7 @@ elf_strptr (Elf *elf, size_t idx, size_t offset) else { Elf64_Shdr *shdr = strscn->shdr.e64 ?: __elf64_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);