From: Mark Wielaard Date: Mon, 15 Sep 2025 21:58:08 +0000 (+0200) Subject: libelf: check ehdr isn't NULL before calling default_ehdr X-Git-Tag: elfutils-0.194~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13153e98ee4f4b4ad2c73c2a747b6c2db984e029;p=thirdparty%2Felfutils.git libelf: check ehdr isn't NULL before calling default_ehdr 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 --- diff --git a/libelf/elf32_updatenull.c b/libelf/elf32_updatenull.c index 3594e8ba..74c27fda 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. */