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.
This commit is contained in:
Gunnar Beutner 2021-05-17 14:45:57 +02:00 committed by Andreas Kling
parent 26e711f953
commit ee6600ea24
Notes: sideshowbarker 2024-07-18 17:56:04 +09:00

View file

@ -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;