1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

LibElf+readelf: Parse ELFs with no program headers correctly

This simply fixes a check which assumed the program header count was
always non zero.
This commit is contained in:
Idan Horowitz 2021-03-29 15:14:41 +03:00 committed by Andreas Kling
parent ba0df27653
commit eab151c994
2 changed files with 21 additions and 17 deletions

View file

@ -95,7 +95,7 @@ bool validate_elf_header(const Elf32_Ehdr& elf_header, size_t file_size, bool ve
return false;
}
if (elf_header.e_phoff < elf_header.e_ehsize || (elf_header.e_shnum != SHN_UNDEF && elf_header.e_shoff < elf_header.e_ehsize)) {
if ((elf_header.e_phnum != 0 && elf_header.e_phoff < elf_header.e_ehsize) || (elf_header.e_shnum != SHN_UNDEF && elf_header.e_shoff < elf_header.e_ehsize)) {
if (verbose) {
dbgln("SHENANIGANS! program header offset ({}) or section header offset ({}) overlap with ELF header!",
elf_header.e_phoff, elf_header.e_shoff);

View file

@ -552,6 +552,9 @@ int main(int argc, char** argv)
printf("\n");
}
if (!elf_image.program_header_count()) {
printf("There are no program headers in this file.\n");
} else {
printf("Program Headers:\n");
printf(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n");
@ -571,6 +574,7 @@ int main(int argc, char** argv)
return IterationDecision::Continue;
});
}
// TODO: Display section to segment mapping
printf("\n");