From 79769ee74e5cf566dc10adb164b87f0a98e33277 Mon Sep 17 00:00:00 2001 From: Itamar Date: Fri, 4 Dec 2020 12:19:50 +0200 Subject: [PATCH] LibELF: Allow elf files with no section header to pass validation --- Libraries/LibELF/Validation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Libraries/LibELF/Validation.cpp b/Libraries/LibELF/Validation.cpp index 8363cb8451..cb042b499c 100644 --- a/Libraries/LibELF/Validation.cpp +++ b/Libraries/LibELF/Validation.cpp @@ -93,7 +93,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_shoff < elf_header.e_ehsize) { + if (elf_header.e_phoff < elf_header.e_ehsize || (elf_header.e_shnum != SHN_UNDEF && elf_header.e_shoff < elf_header.e_ehsize)) { if (verbose) { dbgprintf("SHENANIGANS! program header offset (%d) or section header offset (%d) overlap with ELF header!\n", elf_header.e_phoff, elf_header.e_shoff); @@ -148,7 +148,7 @@ bool validate_elf_header(const Elf32_Ehdr& elf_header, size_t file_size, bool ve return false; } - if (elf_header.e_shoff < end_of_last_program_header) { + if (elf_header.e_shoff != SHN_UNDEF && elf_header.e_shoff < end_of_last_program_header) { if (verbose) { dbgprintf("SHENANIGANS! Section header table begins at file offset %d, which is within program headers [ %d - %zu ]!\n", elf_header.e_shoff, elf_header.e_phoff, end_of_last_program_header);