summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2025-02-09 00:07:13 +0100
committerMark Wielaard <[email protected]>2025-02-14 08:55:10 +0100
commitb38e562a4c907e08171c76b8b2def8464d5a104a (patch)
treeeb3ae5da27b99930b80e234e9583ccd6f85a8047
parent5e5c0394d82c53e97750fe7b18023e6f84157b81 (diff)
readelf: Handle NULL phdr in handle_dynamic_symtab
A corrupt ELF file can have broken program headers, in which case gelf_getphdr returns NULL. This could crash handle_dynamic_symtab while searching for the PT_DYNAMIC phdr. Fix this by checking whether gelf_phdr returns NULL. * src/readelf.c (handle_dynamic_symtab): Check whether gelf_getphdr returns NULL. https://sourceware.org/bugzilla/show_bug.cgi?id=32655 Signed-off-by: Mark Wielaard <[email protected]>
-rw-r--r--src/readelf.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/readelf.c b/src/readelf.c
index c43fda35..21b92a08 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -2912,7 +2912,7 @@ handle_dynamic_symtab (Ebl *ebl)
for (size_t i = 0; i < phnum; ++i)
{
phdr = gelf_getphdr (ebl->elf, i, &phdr_mem);
- if (phdr->p_type == PT_DYNAMIC)
+ if (phdr == NULL || phdr->p_type == PT_DYNAMIC)
break;
}
if (phdr == NULL)