mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:07:35 +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
4 changed files with 21 additions and 15 deletions
|
@ -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()))
|
if (!copy_from_user(strings.data(), list.strings, size.value()))
|
||||||
return false;
|
return false;
|
||||||
for (size_t i = 0; i < list.length; ++i) {
|
for (size_t i = 0; i < list.length; ++i) {
|
||||||
auto string = copy_string_from_user(strings[i]);
|
auto string_or_error = try_copy_kstring_from_user(strings[i]);
|
||||||
if (string.is_null())
|
if (string_or_error.is_error()) {
|
||||||
|
// FIXME: Propagate the error.
|
||||||
return false;
|
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)))
|
if (!output.try_append(move(string)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,10 +32,11 @@ KResultOr<FlatPtr> Process::sys$sethostname(Userspace<const char*> buffer, size_
|
||||||
if (length > 64)
|
if (length > 64)
|
||||||
return ENAMETOOLONG;
|
return ENAMETOOLONG;
|
||||||
return hostname().with_exclusive([&](auto& name) -> KResultOr<FlatPtr> {
|
return hostname().with_exclusive([&](auto& name) -> KResultOr<FlatPtr> {
|
||||||
auto copied_hostname = copy_string_from_user(buffer, length);
|
auto name_or_error = try_copy_kstring_from_user(buffer, length);
|
||||||
if (copied_hostname.is_null())
|
if (name_or_error.is_error())
|
||||||
return EFAULT;
|
return name_or_error.error();
|
||||||
name = move(copied_hostname);
|
// FIXME: Use KString instead of String here.
|
||||||
|
name = name_or_error.value()->view();
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,11 +155,11 @@ KResultOr<FlatPtr> Process::sys$module_unload(Userspace<const char*> user_name,
|
||||||
|
|
||||||
REQUIRE_NO_PROMISES;
|
REQUIRE_NO_PROMISES;
|
||||||
|
|
||||||
auto module_name = copy_string_from_user(user_name, name_length);
|
auto module_name_or_error = try_copy_kstring_from_user(user_name, name_length);
|
||||||
if (module_name.is_null())
|
if (module_name_or_error.is_error())
|
||||||
return EFAULT;
|
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())
|
if (it == g_modules->end())
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
|
|
||||||
|
|
|
@ -41,13 +41,14 @@ KResultOr<FlatPtr> Process::sys$set_process_name(Userspace<const char*> user_nam
|
||||||
REQUIRE_PROMISE(proc);
|
REQUIRE_PROMISE(proc);
|
||||||
if (user_name_length > 256)
|
if (user_name_length > 256)
|
||||||
return ENAMETOOLONG;
|
return ENAMETOOLONG;
|
||||||
auto name = copy_string_from_user(user_name, user_name_length);
|
auto name_or_error = try_copy_kstring_from_user(user_name, user_name_length);
|
||||||
if (name.is_null())
|
if (name_or_error.is_error())
|
||||||
return EFAULT;
|
return name_or_error.error();
|
||||||
// Empty and whitespace-only names only exist to confuse users.
|
// Empty and whitespace-only names only exist to confuse users.
|
||||||
if (name.is_whitespace())
|
if (name_or_error.value()->view().is_whitespace())
|
||||||
return EINVAL;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue