From ee6600ea2407ab557ea020b494ad18f69316a663 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 17 May 2021 14:45:57 +0200 Subject: [PATCH] UE: Don't look up binaries in PATH when the user specified a full path When the user specifies a path such as ./test we'd incorrectly look for the binary in the PATH environment variable and end up executing an incorrect binary (e.g. /bin/test). We should only look up binaries in PATH if the user-specified path does not contain a slash. --- Userland/DevTools/UserspaceEmulator/main.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Userland/DevTools/UserspaceEmulator/main.cpp b/Userland/DevTools/UserspaceEmulator/main.cpp index c826cf13e01..5d341969d01 100644 --- a/Userland/DevTools/UserspaceEmulator/main.cpp +++ b/Userland/DevTools/UserspaceEmulator/main.cpp @@ -26,13 +26,14 @@ int main(int argc, char** argv, char** env) parser.add_positional_argument(arguments, "Command to emulate", "command"); parser.parse(argc, argv); - auto executable_path = Core::find_executable_in_path(arguments[0]); - if (executable_path.is_empty()) { + String executable_path; + if (arguments[0].contains("/"sv)) executable_path = Core::File::real_path_for(arguments[0]); - if (executable_path.is_empty()) { - reportln("Cannot find executable for '{}'.", executable_path); - return 1; - } + else + executable_path = Core::find_executable_in_path(arguments[0]); + if (executable_path.is_empty()) { + reportln("Cannot find executable for '{}'.", arguments[0]); + return 1; } Vector environment;