[PATCH 3/7] libelf: Check __gelf_getehdr_rdlock call doesn't fail in elf_getdata.
Mark Wielaard
mark@klomp.org
Sun May 10 19:53:36 GMT 2020
GCC10 -fanalyzer with -flto notices __gelf_getehdr_rdlock can fail
and that the result of the call in __libelf_set_rawdata_wrlock isn't
checked, which can cause a dereference of NULL.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
libelf/ChangeLog | 5 +++++
libelf/elf_getdata.c | 2 ++
2 files changed, 7 insertions(+)
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 56f5354c..fcea8aa9 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,8 @@
+2020-05-08 Mark Wielaard <mark@klomp.org>
+
+ * elf_getdata.c (__libelf_set_rawdata_wrlock): Check
+ __gelf_getehdr_rdlock return value.
+
2020-04-25 Mark Wielaard <mark@klomp.org>
* elf_compress.c (__libelf_compress): Remove free (out_buf).
diff --git a/libelf/elf_getdata.c b/libelf/elf_getdata.c
index 40fe1694..0d8f8d2e 100644
--- a/libelf/elf_getdata.c
+++ b/libelf/elf_getdata.c
@@ -271,6 +271,8 @@ __libelf_set_rawdata_wrlock (Elf_Scn *scn)
{
GElf_Ehdr ehdr_mem;
GElf_Ehdr *ehdr = __gelf_getehdr_rdlock (elf, &ehdr_mem);
+ if (unlikely (ehdr == NULL))
+ return 1;
entsize = SH_ENTSIZE_HASH (ehdr);
}
else
--
2.20.1
More information about the Elfutils-devel
mailing list