]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: check ehdr isn't NULL before calling default_ehdr
authorMark Wielaard <mark@klomp.org>
Mon, 15 Sep 2025 21:58:08 +0000 (23:58 +0200)
committerMark Wielaard <mark@klomp.org>
Mon, 15 Sep 2025 22:03:19 +0000 (00:03 +0200)
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 <mark@klomp.org>
libelf/elf32_updatenull.c

index 3594e8bad6c0fc87dafba5302b00ab691910b515..74c27fdaa7b53da795cfc1b23fc86119f9a86764 100644 (file)
@@ -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.  */