Kernel: Migrate sys$unveil to use the KString API

This avoids potential unhandled OOM that's possible with the old
copy_string_from_user API.
This commit is contained in:
Brian Gianforcaro 2021-07-23 08:21:10 -07:00 committed by Andreas Kling
parent 2e7728bb05
commit baec9e2d2d
Notes: sideshowbarker 2024-07-18 08:29:15 +09:00

View File

@ -53,13 +53,17 @@ KResultOr<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params
if (path.is_empty() || !path.view().starts_with('/'))
return EINVAL;
auto permissions = copy_string_from_user(params.permissions);
if (permissions.is_null())
return EFAULT;
OwnPtr<KString> permissions;
{
auto permissions_or_error = try_copy_kstring_from_user(params.permissions);
if (permissions_or_error.is_error())
return permissions_or_error.error();
permissions = permissions_or_error.release_value();
}
// Let's work out permissions first...
unsigned new_permissions = 0;
for (const char permission : permissions) {
for (const char permission : permissions->view()) {
switch (permission) {
case 'r':
new_permissions |= UnveilAccess::Read;