default_ehdr assumes the passed ehdr pointer is not NULL and can be
directly dereferenced. But getehdr can return NULL. So explicitly
check.

        * libelf/elf32_updatenull.c (updatenull_wrlock): Check ehdr is
        not NULL.

https://sourceware.org/bugzilla/show_bug.cgi?id=33433

Signed-off-by: Mark Wielaard <[email protected]>
---
 libelf/elf32_updatenull.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libelf/elf32_updatenull.c b/libelf/elf32_updatenull.c
index 3594e8bad6c0..74c27fdaa7b5 100644
--- a/libelf/elf32_updatenull.c
+++ b/libelf/elf32_updatenull.c
@@ -135,7 +135,8 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (Elf *elf, int 
*change_bop, size_t shnum)
   ehdr = __elfw2(LIBELFBITS,getehdr_wrlock) (elf);
 
   /* Set the default values.  */
-  if (ELFW(default_ehdr,LIBELFBITS) (elf, ehdr, shnum, change_bop) != 0)
+  if (ehdr == NULL
+      || ELFW(default_ehdr,LIBELFBITS) (elf, ehdr, shnum, change_bop) != 0)
     return -1;
 
   /* At least the ELF header is there.  */
-- 
2.51.0

Reply via email to