diff options
author | Andreas Kling <kling@serenityos.org> | 2021-08-14 23:00:06 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-15 12:44:35 +0200 |
commit | 0f6f86338294899fcd0e8cd9961fafbf604fa197 (patch) | |
tree | 3d72edfe04df8a8516bd0ab58ce419a42f551a14 /Kernel/Syscalls | |
parent | 9509433e25455bf8ee98a9ea718c9b4d4c84c7f6 (diff) | |
download | serenity-0f6f86338294899fcd0e8cd9961fafbf604fa197.zip |
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.
Diffstat (limited to 'Kernel/Syscalls')
-rw-r--r-- | Kernel/Syscalls/execve.cpp | 8 | ||||
-rw-r--r-- | Kernel/Syscalls/hostname.cpp | 9 | ||||
-rw-r--r-- | Kernel/Syscalls/module.cpp | 8 | ||||
-rw-r--r-- | 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<FlatPtr> Process::sys$execve(Userspace<const Syscall::SC_execve_params if (!copy_from_user(strings.data(), list.strings, size.value())) return false; for (size_t i = 0; i < list.length; ++i) { - auto string = copy_string_from_user(strings[i]); - if (string.is_null()) + auto string_or_error = 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. + auto string = String(string_or_error.value()->view()); 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<FlatPtr> Process::sys$sethostname(Userspace<const char*> buffer, size_ if (length > 64) return ENAMETOOLONG; return hostname().with_exclusive([&](auto& name) -> KResultOr<FlatPtr> { - 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<FlatPtr> Process::sys$module_unload(Userspace<const char*> 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<FlatPtr> Process::sys$set_process_name(Userspace<const char*> 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; } |