From cbe5aeb917eaa96909b4ccf2b41a145b8e3ab00b Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Wed, 7 Jun 2023 18:12:00 +0100 Subject: [PATCH] LibCore: Ensure `exec()` keeps a reference to the executable path When called with `SearchInPath::Yes`, calls to `Core::System::exec()` would fail. The value returned from `resolve_executable_from_environment()` was assigned to a StringView, but the original reference was not kept, causing the StringView to appear empty. --- Userland/Libraries/LibCore/System.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 3717349f2b..193d0754a7 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -1263,14 +1263,15 @@ ErrorOr exec(StringView filename, ReadonlySpan arguments, Sear }; StringView exec_filename; - + String resolved_executable_path; if (search_in_path == SearchInPath::Yes) { auto executable_or_error = resolve_executable_from_environment(filename); if (executable_or_error.is_error()) return executable_or_error.release_error(); - exec_filename = executable_or_error.value(); + resolved_executable_path = executable_or_error.release_value(); + exec_filename = resolved_executable_path; } else { exec_filename = filename; }