From d6a3f1fcd7e5458cdf0cc777e159ebadebbd2cd1 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Sun, 6 Jun 2021 01:13:25 +0200 Subject: Kernel: Simplify `execve` shebang argument handling --- Kernel/Syscalls/execve.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'Kernel/Syscalls') diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index ba6b0f72cc..8c4a9179fa 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -846,14 +846,11 @@ KResult Process::exec(String path, Vector arguments, Vector envi // 1) #! interpreted file auto shebang_result = find_shebang_interpreter_for_executable(first_page, nread_or_error.value()); if (!shebang_result.is_error()) { - Vector new_arguments(shebang_result.value()); - - new_arguments.append(path); - - arguments.remove(0); - new_arguments.append(move(arguments)); - - return exec(shebang_result.value().first(), move(new_arguments), move(environment), ++recursion_depth); + auto shebang_words = shebang_result.release_value(); + auto shebang_path = shebang_words.first(); + if (!arguments.try_prepend(move(shebang_words))) + return ENOMEM; + return exec(shebang_path, move(arguments), move(environment), ++recursion_depth); } // #2) ELF32 for i386 -- cgit v1.2.3