]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: Set dst to zero on failure in __elf_getphdrnum_rdlock
authorMark Wielaard <mark@klomp.org>
Sun, 1 Nov 2020 17:51:02 +0000 (18:51 +0100)
committerMark Wielaard <mark@klomp.org>
Fri, 6 Nov 2020 17:39:40 +0000 (18:39 +0100)
GCC with -flto finds some (very) unlikely error paths. It flags callers
of __elf_getphdrnum_chk_rdlock with *dst not yet set because an internal
call to __elf_getphdrnum_rdlock might not initialize *dst either in one
particular failure path. The sanity check that __elf_getphdrnum_chk_rdlock
then performs might happen against uninitialized data. So just set *dst
to zero on failure in __elf_getphdrnum_rdlock so any caller can simply
check either the result/error code or whether *dst is zero or not.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libelf/ChangeLog
libelf/elf_getphdrnum.c

index 7bd15a284a5403468687493ccd9181c01e1af2b8..aee1ffff55337575b0059e92a9a73f35eb7eb2a1 100644 (file)
@@ -1,3 +1,8 @@
+2020-11-01  Mark Wielaard  <mark@klomp.org>
+
+       * elf_getphdrnum.c (__elf_getphdrnum_rdlock): Set *dst to zero on
+       error.
+
 2020-11-01  Mark Wielaard  <mark@klomp.org>
 
        * libelfP.h (__libelf_data_type): Take an GElf_Ehdr instead of an
index 53617dfc7f61383b98525fbeb12501dcc95d415a..60ebec58cb0c70320955868bc7386b218c1a15f4 100644 (file)
@@ -44,6 +44,7 @@ __elf_getphdrnum_rdlock (Elf *elf, size_t *dst)
  if (unlikely (elf->state.elf64.ehdr == NULL))
    {
      /* Maybe no ELF header was created yet.  */
+     *dst = 0;
      __libelf_seterrno (ELF_E_WRONG_ORDER_EHDR);
      return -1;
    }