summaryrefslogtreecommitdiff
path: root/libelf
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2020-05-09 05:02:25 +0200
committerMark Wielaard <mark@klomp.org>2020-05-14 14:30:57 +0200
commit24d6569408c2039a97054f3e6999cb174c076242 (patch)
treee5a222f0530f8d48247bf605d8ba966798d52357 /libelf
parent59587b33d472ee809250ffba77e38030939fc519 (diff)
downloadelfutils-24d6569408c2039a97054f3e6999cb174c076242.tar.gz
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 <mark@klomp.org>
Diffstat (limited to 'libelf')
-rw-r--r--libelf/ChangeLog4
-rw-r--r--libelf/elf_strptr.c2
2 files changed, 5 insertions, 1 deletions
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index fcea8aa9..fd5518dc 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,5 +1,9 @@
2020-05-08 Mark Wielaard <mark@klomp.org>
+ * elf_strptr.c (elf_strptr): Check shdr is not NULL.
+
+2020-05-08 Mark Wielaard <mark@klomp.org>
+
* elf_getdata.c (__libelf_set_rawdata_wrlock): Check
__gelf_getehdr_rdlock return value.
diff --git a/libelf/elf_strptr.c b/libelf/elf_strptr.c
index e72a3a36..c7271707 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);