Util: Fix crash reading invalid ELFs
Vicki Pfau vi@endrift.com
Fri, 31 Jan 2020 18:03:48 -0800
2 files changed,
4 insertions(+),
0 deletions(-)
M
src/util/elf-read.c
→
src/util/elf-read.c
@@ -84,6 +84,9 @@ void ELFGetProgramHeaders(struct ELF* elf, struct ELFProgramHeaders* ph) {
ELFProgramHeadersClear(ph); Elf32_Ehdr* hdr = elf32_getehdr(elf->e); Elf32_Phdr* phdr = elf32_getphdr(elf->e); + if (!hdr || !phdr) { + return; + } ELFProgramHeadersResize(ph, hdr->e_phnum); memcpy(ELFProgramHeadersGetPointer(ph, 0), phdr, sizeof(*phdr) * hdr->e_phnum); }