From 0f6f86338294899fcd0e8cd9961fafbf604fa197 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 14 Aug 2021 23:00:06 +0200 Subject: [PATCH] Kernel: Convert remaining users of copy_string_from_user() This patch replaces the remaining users of this API with the new try_copy_kstring_from_user() instead. Note that we still convert to a String for continued processing, and I've added FIXME about continuing work on using KString all the way. --- Kernel/Syscalls/execve.cpp | 8 ++++++-- Kernel/Syscalls/hostname.cpp | 9 +++++---- Kernel/Syscalls/module.cpp | 8 ++++---- Kernel/Syscalls/process.cpp | 11 ++++++----- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index eef9d081de..a9ff468620 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -970,9 +970,13 @@ KResultOr Process::sys$execve(Userspaceview()); if (!output.try_append(move(string))) return false; } diff --git a/Kernel/Syscalls/hostname.cpp b/Kernel/Syscalls/hostname.cpp index 19ca6a473c..d5ce98474a 100644 --- a/Kernel/Syscalls/hostname.cpp +++ b/Kernel/Syscalls/hostname.cpp @@ -32,10 +32,11 @@ KResultOr Process::sys$sethostname(Userspace buffer, size_ if (length > 64) return ENAMETOOLONG; return hostname().with_exclusive([&](auto& name) -> KResultOr { - auto copied_hostname = copy_string_from_user(buffer, length); - if (copied_hostname.is_null()) - return EFAULT; - name = move(copied_hostname); + auto name_or_error = try_copy_kstring_from_user(buffer, length); + if (name_or_error.is_error()) + return name_or_error.error(); + // FIXME: Use KString instead of String here. + name = name_or_error.value()->view(); return 0; }); } diff --git a/Kernel/Syscalls/module.cpp b/Kernel/Syscalls/module.cpp index 6cd23a53d3..471dffd803 100644 --- a/Kernel/Syscalls/module.cpp +++ b/Kernel/Syscalls/module.cpp @@ -155,11 +155,11 @@ KResultOr Process::sys$module_unload(Userspace user_name, REQUIRE_NO_PROMISES; - auto module_name = copy_string_from_user(user_name, name_length); - if (module_name.is_null()) - return EFAULT; + auto module_name_or_error = try_copy_kstring_from_user(user_name, name_length); + if (module_name_or_error.is_error()) + return module_name_or_error.error(); - auto it = g_modules->find(module_name); + auto it = g_modules->find(module_name_or_error.value()->view()); if (it == g_modules->end()) return ENOENT; diff --git a/Kernel/Syscalls/process.cpp b/Kernel/Syscalls/process.cpp index 3a0c7acb78..200f8b1bb8 100644 --- a/Kernel/Syscalls/process.cpp +++ b/Kernel/Syscalls/process.cpp @@ -41,13 +41,14 @@ KResultOr Process::sys$set_process_name(Userspace user_nam REQUIRE_PROMISE(proc); if (user_name_length > 256) return ENAMETOOLONG; - auto name = copy_string_from_user(user_name, user_name_length); - if (name.is_null()) - return EFAULT; + auto name_or_error = try_copy_kstring_from_user(user_name, user_name_length); + if (name_or_error.is_error()) + return name_or_error.error(); // Empty and whitespace-only names only exist to confuse users. - if (name.is_whitespace()) + if (name_or_error.value()->view().is_whitespace()) return EINVAL; - m_name = move(name); + // FIXME: There's a String copy here. Process::m_name should be a KString. + m_name = name_or_error.value()->view(); return 0; }