summaryrefslogtreecommitdiff
path: root/Userland/DevTools/UserspaceEmulator
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-05-17 14:45:57 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-17 19:34:53 +0200
commitee6600ea2407ab557ea020b494ad18f69316a663 (patch)
treec9c4fb3089ab755e0cc15a6ae5b566088eb3141f /Userland/DevTools/UserspaceEmulator
parent26e711f9534e8d8d424cfde4b6422dc9d690daf5 (diff)
downloadserenity-ee6600ea2407ab557ea020b494ad18f69316a663.zip
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.
Diffstat (limited to 'Userland/DevTools/UserspaceEmulator')
-rw-r--r--Userland/DevTools/UserspaceEmulator/main.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/Userland/DevTools/UserspaceEmulator/main.cpp b/Userland/DevTools/UserspaceEmulator/main.cpp
index c826cf13e0..5d341969d0 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<String> environment;