From d46f12aa8efbd194136d305bf2cb37e3e499b4af Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Fri, 31 Jan 2020 18:03:48 -0800 Subject: [PATCH] Util: Fix crash reading invalid ELFs --- CHANGES | 1 + src/util/elf-read.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGES b/CHANGES index 4b9e1c695..fde656aef 100644 --- a/CHANGES +++ b/CHANGES @@ -23,6 +23,7 @@ Other fixes: - Qt: Fix crash unloading shaders - Qt: Fix toggled actions on gamepads (fixes mgba.io/i/1650) - Qt: Fix extraneous dialog (fixes mgba.io/i/1654) + - Util: Fix crash reading invalid ELFs Misc: - Qt: Renderer can be changed while a game is running diff --git a/src/util/elf-read.c b/src/util/elf-read.c index 8ac38774d..520c01ca3 100644 --- a/src/util/elf-read.c +++ b/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); }