mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
Kernel: Improve arguments retrieval error propagation in sys$execve()
Instead of turning any arguments related error into an EFAULT, we now propagate the innermost error during arguments retrieval.
This commit is contained in:
parent
6e3381ac32
commit
84addef10f
1 changed files with 12 additions and 19 deletions
|
@ -933,39 +933,32 @@ KResultOr<FlatPtr> Process::sys$execve(Userspace<const Syscall::SC_execve_params
|
||||||
path = path_arg.value()->view();
|
path = path_arg.value()->view();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto copy_user_strings = [](const auto& list, auto& output) {
|
auto copy_user_strings = [](const auto& list, auto& output) -> KResult {
|
||||||
if (!list.length)
|
if (!list.length)
|
||||||
return true;
|
return KSuccess;
|
||||||
Checked<size_t> size = sizeof(*list.strings);
|
Checked<size_t> size = sizeof(*list.strings);
|
||||||
size *= list.length;
|
size *= list.length;
|
||||||
if (size.has_overflow())
|
if (size.has_overflow())
|
||||||
return false;
|
return EOVERFLOW;
|
||||||
Vector<Syscall::StringArgument, 32> strings;
|
Vector<Syscall::StringArgument, 32> strings;
|
||||||
if (!strings.try_resize(list.length))
|
if (!strings.try_resize(list.length))
|
||||||
return false;
|
return ENOMEM;
|
||||||
if (copy_from_user(strings.data(), list.strings, size.value()).is_error())
|
TRY(copy_from_user(strings.data(), list.strings, size.value()));
|
||||||
return false;
|
|
||||||
for (size_t i = 0; i < list.length; ++i) {
|
for (size_t i = 0; i < list.length; ++i) {
|
||||||
auto string_or_error = try_copy_kstring_from_user(strings[i]);
|
auto string = TRY(try_copy_kstring_from_user(strings[i]));
|
||||||
if (string_or_error.is_error()) {
|
|
||||||
// FIXME: Propagate the error.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// FIXME: Don't convert to String here, use KString all the way.
|
// FIXME: Don't convert to String here, use KString all the way.
|
||||||
auto string = String(string_or_error.value()->view());
|
auto ak_string = String(string->view());
|
||||||
if (!output.try_append(move(string)))
|
if (!output.try_append(move(ak_string)))
|
||||||
return false;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
return true;
|
return KSuccess;
|
||||||
};
|
};
|
||||||
|
|
||||||
Vector<String> arguments;
|
Vector<String> arguments;
|
||||||
if (!copy_user_strings(params.arguments, arguments))
|
TRY(copy_user_strings(params.arguments, arguments));
|
||||||
return EFAULT;
|
|
||||||
|
|
||||||
Vector<String> environment;
|
Vector<String> environment;
|
||||||
if (!copy_user_strings(params.environment, environment))
|
TRY(copy_user_strings(params.environment, environment));
|
||||||
return EFAULT;
|
|
||||||
|
|
||||||
auto result = exec(move(path), move(arguments), move(environment));
|
auto result = exec(move(path), move(arguments), move(environment));
|
||||||
VERIFY(result.is_error()); // We should never continue after a successful exec!
|
VERIFY(result.is_error()); // We should never continue after a successful exec!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue