diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index 5e83ef9dec..9e0cdb00a6 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -933,39 +933,32 @@ KResultOr Process::sys$execve(Userspaceview(); } - auto copy_user_strings = [](const auto& list, auto& output) { + auto copy_user_strings = [](const auto& list, auto& output) -> KResult { if (!list.length) - return true; + return KSuccess; Checked size = sizeof(*list.strings); size *= list.length; if (size.has_overflow()) - return false; + return EOVERFLOW; Vector strings; if (!strings.try_resize(list.length)) - return false; - if (copy_from_user(strings.data(), list.strings, size.value()).is_error()) - return false; + return ENOMEM; + TRY(copy_from_user(strings.data(), list.strings, size.value())); for (size_t i = 0; i < list.length; ++i) { - auto string_or_error = try_copy_kstring_from_user(strings[i]); - if (string_or_error.is_error()) { - // FIXME: Propagate the error. - return false; - } + auto string = TRY(try_copy_kstring_from_user(strings[i])); // FIXME: Don't convert to String here, use KString all the way. - auto string = String(string_or_error.value()->view()); - if (!output.try_append(move(string))) - return false; + auto ak_string = String(string->view()); + if (!output.try_append(move(ak_string))) + return ENOMEM; } - return true; + return KSuccess; }; Vector arguments; - if (!copy_user_strings(params.arguments, arguments)) - return EFAULT; + TRY(copy_user_strings(params.arguments, arguments)); Vector environment; - if (!copy_user_strings(params.environment, environment)) - return EFAULT; + TRY(copy_user_strings(params.environment, environment)); auto result = exec(move(path), move(arguments), move(environment)); VERIFY(result.is_error()); // We should never continue after a successful exec!