* [PATCH] libelf: Set dst to zero on failure in __elf_getphdrnum_rdlock
@ 2020-11-01 18:42 Mark Wielaard
2020-11-06 17:48 ` Mark Wielaard
0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2020-11-01 18:42 UTC (permalink / raw)
To: elfutils-devel; +Cc: Mark Wielaard
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 | 5 +++++
libelf/elf_getphdrnum.c | 1 +
2 files changed, 6 insertions(+)
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 7bd15a28..aee1ffff 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -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
diff --git a/libelf/elf_getphdrnum.c b/libelf/elf_getphdrnum.c
index 53617dfc..60ebec58 100644
--- a/libelf/elf_getphdrnum.c
+++ b/libelf/elf_getphdrnum.c
@@ -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;
}
--
2.18.4
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] libelf: Set dst to zero on failure in __elf_getphdrnum_rdlock
2020-11-01 18:42 [PATCH] libelf: Set dst to zero on failure in __elf_getphdrnum_rdlock Mark Wielaard
@ 2020-11-06 17:48 ` Mark Wielaard
0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2020-11-06 17:48 UTC (permalink / raw)
To: elfutils-devel
On Sun, 2020-11-01 at 19:42 +0100, Mark Wielaard wrote:
> 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.
Pushed.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-11-06 17:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-01 18:42 [PATCH] libelf: Set dst to zero on failure in __elf_getphdrnum_rdlock Mark Wielaard
2020-11-06 17:48 ` Mark Wielaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).