From 30abfc2b213c3d4782e0d2d704f6b4c8b73c04cf Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Sun, 13 Jun 2021 17:20:56 +0200 Subject: [PATCH] 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 --- Kernel/Syscalls/execve.cpp | 1 + 1 file changed, 1 insertion(+) 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 arguments, Vector 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);