summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-07-23 08:21:10 -0700
committerAndreas Kling <kling@serenityos.org>2021-07-23 19:02:25 +0200
commitbaec9e2d2d2b8a082ff3ebd1ac621f6d96eaf94d (patch)
tree0e8b4b42c9587ce5ee0a0d5a71e3d87354688c0f /Kernel/Syscalls
parent2e7728bb057f6f4bfe2cc856605f7fc9fcb9bec2 (diff)
downloadserenity-baec9e2d2d2b8a082ff3ebd1ac621f6d96eaf94d.zip
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.
Diffstat (limited to 'Kernel/Syscalls')
-rw-r--r--Kernel/Syscalls/unveil.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/Kernel/Syscalls/unveil.cpp b/Kernel/Syscalls/unveil.cpp
index 8d0d498f5e..7c7bfb7b95 100644
--- a/Kernel/Syscalls/unveil.cpp
+++ b/Kernel/Syscalls/unveil.cpp
@@ -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;