mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
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
This commit is contained in:
parent
26250779d1
commit
30abfc2b21
Notes:
sideshowbarker
2024-07-18 12:17:43 +09:00
Author: https://github.com/gmta Commit: https://github.com/SerenityOS/serenity/commit/30abfc2b213 Pull-request: https://github.com/SerenityOS/serenity/pull/8039
1 changed files with 1 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue