mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 17:00:19 +02:00
ELFParser: Sanity check ELF program headers
Malformed ELF files could parse in a bad offset.
This commit is contained in:
1 file changed
+9
-1
@@ -45,7 +45,9 @@ struct ELFParser {
|
||||
}
|
||||
|
||||
// Reset to beginning
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
if (lseek(fd, 0, SEEK_SET) == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t header[5];
|
||||
if (pread(fd, header, sizeof(header), 0) == -1) {
|
||||
@@ -146,6 +148,12 @@ struct ELFParser {
|
||||
return false;
|
||||
}
|
||||
|
||||
// sanity check program header offset size.
|
||||
if (ehdr.e_phoff > Size || (ehdr.e_phentsize * ehdr.e_phnum) > (Size - ehdr.e_phoff)) {
|
||||
LogMan::Msg::EFmt("Program headers exceeds size of program");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type == ::ELFLoader::ELFContainer::TYPE_X86_32) {
|
||||
fextl::vector<Elf32_Phdr> phdrs32(ehdr.e_phnum);
|
||||
|
||||
|
||||
Reference in new issue
Block a user