summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2021-06-13 17:20:56 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-13 21:19:51 +0200
commit30abfc2b213c3d4782e0d2d704f6b4c8b73c04cf (patch)
treee5533bccb2083d82d8182efef8b4fbf87dc97fe7
parent26250779d1ff5d583056444d67e585c24450c2c0 (diff)
downloadserenity-30abfc2b213c3d4782e0d2d704f6b4c8b73c04cf.zip
Kernel: Pass absolute path to shebang interpreter
When you invoke a binary with a shebang line, the `execve` syscall makes sure to pass along command line arguments to the shebang interpreter including the path to the binary to execute. This does not work well when the binary lives in $PATH. For example, given this script living in `/usr/local/bin/my-script`: #!/bin/my-interpreter echo "well hello friends" When executing it as `my-script` from outside `/usr/local/bin/`, it is executed as `/bin/my-interpreter my-script`. To make sure that the interpreter can find the binary to execute, we need to replace the first argument with an absolute path to the binary, so that the resulting command is: /bin/my-interpreter /usr/local/bin/my-script
-rw-r--r--Kernel/Syscalls/execve.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp
index d5714eef1f..20ae7dcf42 100644
--- a/Kernel/Syscalls/execve.cpp
+++ b/Kernel/Syscalls/execve.cpp
@@ -849,6 +849,7 @@ KResult Process::exec(String path, Vector<String> arguments, Vector<String> envi
if (!shebang_result.is_error()) {
auto shebang_words = shebang_result.release_value();
auto shebang_path = shebang_words.first();
+ arguments[0] = move(path);
if (!arguments.try_prepend(move(shebang_words)))
return ENOMEM;
return exec(move(shebang_path), move(arguments), move(environment), ++recursion_depth);