mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
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.
This commit is contained in:
parent
9509433e25
commit
0f6f863382
Notes:
sideshowbarker
2024-07-18 05:40:15 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/0f6f8633829
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue