mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:38:11 +00:00
LibELF+Lagom: Work towards getting LibELF in Lagom
Mostly -Wformat fixes, some of which pointed out real (if benign) bugs.
This commit is contained in:
parent
872834320a
commit
0586924bbd
6 changed files with 33 additions and 32 deletions
|
@ -79,7 +79,7 @@ bool validate_elf_header(const Elf32_Ehdr& elf_header, size_t file_size)
|
|||
}
|
||||
|
||||
if (sizeof(Elf32_Ehdr) != elf_header.e_ehsize) {
|
||||
dbgprintf("File has incorrect ELF header size..? (%d), expected (%d)!\n", elf_header.e_ehsize, sizeof(Elf32_Ehdr));
|
||||
dbgprintf("File has incorrect ELF header size..? (%d), expected (%zu)!\n", elf_header.e_ehsize, sizeof(Elf32_Ehdr));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -101,24 +101,24 @@ bool validate_elf_header(const Elf32_Ehdr& elf_header, size_t file_size)
|
|||
}
|
||||
|
||||
if (0 != elf_header.e_phnum && sizeof(Elf32_Phdr) != elf_header.e_phentsize) {
|
||||
dbgprintf("File has incorrect program header size..? (%d), expected (%d).\n", elf_header.e_phentsize, sizeof(Elf32_Phdr));
|
||||
dbgprintf("File has incorrect program header size..? (%d), expected (%zu).\n", elf_header.e_phentsize, sizeof(Elf32_Phdr));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sizeof(Elf32_Shdr) != elf_header.e_shentsize) {
|
||||
dbgprintf("File has incorrect section header size..? (%d), expected (%d).\n", elf_header.e_shentsize, sizeof(Elf32_Shdr));
|
||||
dbgprintf("File has incorrect section header size..? (%d), expected (%zu).\n", elf_header.e_shentsize, sizeof(Elf32_Shdr));
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t end_of_last_program_header = elf_header.e_phoff + (elf_header.e_phnum * elf_header.e_phentsize);
|
||||
if (end_of_last_program_header > file_size) {
|
||||
dbgprintf("SHENANIGANS! End of last program header (%d) is past the end of the file!\n", end_of_last_program_header);
|
||||
dbgprintf("SHENANIGANS! End of last program header (%zu) is past the end of the file!\n", end_of_last_program_header);
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t end_of_last_section_header = elf_header.e_shoff + (elf_header.e_shnum * elf_header.e_shentsize);
|
||||
if (end_of_last_section_header > file_size) {
|
||||
dbgprintf("SHENANIGANS! End of last section header (%d) is past the end of the file!\n", end_of_last_section_header);
|
||||
dbgprintf("SHENANIGANS! End of last section header (%zu) is past the end of the file!\n", end_of_last_section_header);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -153,12 +153,12 @@ bool validate_program_headers(const Elf32_Ehdr& elf_header, size_t file_size, u8
|
|||
switch (program_header.p_type) {
|
||||
case PT_INTERP:
|
||||
if (ET_DYN != elf_header.e_type) {
|
||||
dbgprintf("Found PT_INTERP header (%d) in non-DYN ELF object! What? We can't handle this!\n", header_index);
|
||||
dbgprintf("Found PT_INTERP header (%zu) in non-DYN ELF object! What? We can't handle this!\n", header_index);
|
||||
return false;
|
||||
}
|
||||
// We checked above that file_size was >= buffer size. We only care about buffer size anyway, we're trying to read this!
|
||||
if (program_header.p_offset + program_header.p_filesz > buffer_size) {
|
||||
dbgprintf("Found PT_INTERP header (%d), but the .interp section was not within our buffer :( Your program will not be loaded today.\n", header_index);
|
||||
dbgprintf("Found PT_INTERP header (%zu), but the .interp section was not within our buffer :( Your program will not be loaded today.\n", header_index);
|
||||
return false;
|
||||
}
|
||||
interpreter_path = String((const char*)&buffer[program_header.p_offset], program_header.p_filesz - 1);
|
||||
|
@ -169,17 +169,17 @@ bool validate_program_headers(const Elf32_Ehdr& elf_header, size_t file_size, u8
|
|||
case PT_PHDR:
|
||||
case PT_TLS:
|
||||
if (program_header.p_offset + program_header.p_filesz > file_size) {
|
||||
dbgprintf("SHENANIGANS! Program header %d segment leaks beyond end of file!\n", header_index);
|
||||
dbgprintf("SHENANIGANS! Program header %zu segment leaks beyond end of file!\n", header_index);
|
||||
return false;
|
||||
}
|
||||
if ((program_header.p_flags & PF_X) && (program_header.p_flags & PF_W)) {
|
||||
dbgprintf("SHENANIGANS! Program header %d segment is marked write and execute\n", header_index);
|
||||
dbgprintf("SHENANIGANS! Program header %zu segment is marked write and execute\n", header_index);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Not handling other program header types in other code so... let's not surprise them
|
||||
dbgprintf("Found program header (%d) of unrecognized type %x!\n", header_index, program_header.p_type);
|
||||
dbgprintf("Found program header (%zu) of unrecognized type %x!\n", header_index, program_header.p_type);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue