1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:34:59 +00:00

LibELF: Use StringBuilders instead of Strings for the interpreter path

This is required for the Kernel's usage of LibELF, since Strings do not
expose allocation failure.
This commit is contained in:
Idan Horowitz 2022-01-13 18:50:17 +02:00 committed by Andreas Kling
parent fb3e46e930
commit 3e959618c3
8 changed files with 36 additions and 18 deletions

View file

@ -298,12 +298,13 @@ int main(int argc, char** argv)
return -1;
}
String interpreter_path;
if (!ELF::validate_program_headers(*(const ElfW(Ehdr)*)elf_image_data.data(), elf_image_data.size(), (const u8*)elf_image_data.data(), elf_image_data.size(), &interpreter_path)) {
StringBuilder interpreter_path_builder;
auto result_or_error = ELF::validate_program_headers(*(const ElfW(Ehdr)*)elf_image_data.data(), elf_image_data.size(), (const u8*)elf_image_data.data(), elf_image_data.size(), &interpreter_path_builder);
if (result_or_error.is_error() || !result_or_error.value()) {
warnln("Invalid ELF headers");
return -1;
}
auto interpreter_path = interpreter_path_builder.string_view();
auto& header = *reinterpret_cast<const ElfW(Ehdr)*>(elf_image_data.data());
@ -311,7 +312,7 @@ int main(int argc, char** argv)
if (elf_image.is_dynamic()) {
if (interpreter_path.is_null()) {
interpreter_path = "/usr/lib/Loader.so";
interpreter_path = "/usr/lib/Loader.so"sv;
warnln("Warning: Dynamic ELF object has no interpreter path. Using: {}", interpreter_path);
}