]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: Check __gelf_getehdr_rdlock call doesn't fail in elf_getdata.
authorMark Wielaard <mark@klomp.org>
Sat, 9 May 2020 01:41:56 +0000 (03:41 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 14 May 2020 12:30:57 +0000 (14:30 +0200)
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
libelf/elf_getdata.c

index 56f5354c5a7d98db0116f03d968a8853a9bf5685..fcea8aa90d51fe59cf2486e407893d913072b080 100644 (file)
@@ -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).
index 40fe16945502e4924b21114d83520ebb4d705e23..0d8f8d2eec54cbec0a0e2993d45e1ab437a7c8b5 100644 (file)
@@ -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