From 735da58d44383389b9aacfdb03f4fa945ce8d665 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Fri, 29 Oct 2021 21:21:26 +0200 Subject: [PATCH] Kernel: Avoid OpenFileDescription::absolute_path --- Kernel/Process.cpp | 8 +++++--- Kernel/Syscalls/execve.cpp | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 449ddc3828..53e38e5f90 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -565,9 +565,11 @@ bool Process::dump_perfcore() // Try to generate a filename which isn't already used. auto base_filename = String::formatted("{}_{}", name(), pid().value()); - auto description_or_error = VirtualFileSystem::the().open(String::formatted("{}.profile", base_filename), O_CREAT | O_EXCL, 0400, current_directory(), UidAndGid { uid(), gid() }); + auto perfcore_filename = String::formatted("{}.profile", base_filename); + auto description_or_error = VirtualFileSystem::the().open(perfcore_filename, O_CREAT | O_EXCL, 0400, current_directory(), UidAndGid { uid(), gid() }); for (size_t attempt = 1; attempt < 10 && description_or_error.is_error(); ++attempt) - description_or_error = VirtualFileSystem::the().open(String::formatted("{}.{}.profile", base_filename, attempt), O_CREAT | O_EXCL, 0400, current_directory(), UidAndGid { uid(), gid() }); + perfcore_filename = String::formatted("{}.{}.profile", base_filename, attempt); + description_or_error = VirtualFileSystem::the().open(perfcore_filename, O_CREAT | O_EXCL, 0400, current_directory(), UidAndGid { uid(), gid() }); if (description_or_error.is_error()) { dbgln("Failed to generate perfcore for pid {}: Could not generate filename for the perfcore file.", pid().value()); return false; @@ -596,7 +598,7 @@ bool Process::dump_perfcore() return false; } - dbgln("Wrote perfcore for pid {} to {}", pid().value(), description.absolute_path()); + dbgln("Wrote perfcore for pid {} to {}", pid().value(), perfcore_filename); return true; } diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index ac0529ab87..dd94d6fb20 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -739,19 +739,19 @@ KResultOr> Process::find_elf_interpreter_for_executa auto elf_header = (ElfW(Ehdr)*)first_page; if (!ELF::validate_elf_header(*elf_header, interp_metadata.size)) { - dbgln("exec({}): Interpreter ({}) has invalid ELF header", path, interpreter_description->absolute_path()); + dbgln("exec({}): Interpreter ({}) has invalid ELF header", path, interpreter_path); return ENOEXEC; } // Not using KResultOr here because we'll want to do the same thing in userspace in the RTLD String interpreter_interpreter_path; if (!ELF::validate_program_headers(*elf_header, interp_metadata.size, (u8*)first_page, nread, &interpreter_interpreter_path)) { - dbgln("exec({}): Interpreter ({}) has invalid ELF Program headers", path, interpreter_description->absolute_path()); + dbgln("exec({}): Interpreter ({}) has invalid ELF Program headers", path, interpreter_path); return ENOEXEC; } if (!interpreter_interpreter_path.is_empty()) { - dbgln("exec({}): Interpreter ({}) has its own interpreter ({})! No thank you!", path, interpreter_description->absolute_path(), interpreter_interpreter_path); + dbgln("exec({}): Interpreter ({}) has its own interpreter ({})! No thank you!", path, interpreter_path, interpreter_interpreter_path); return ELOOP; }