mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:38:11 +00:00
Kernel: Don't allocate memory for names of processes and threads
Instead, use the FixedCharBuffer class to ensure we always use a static buffer storage for these names. This ensures that if a Process or a Thread were created, there's a guarantee that setting a new name will never fail, as only copying of strings should be done to that static storage. The limits which are set are 32 characters for processes' names and 64 characters for thread names - this is because threads' names could be more verbose than processes' names.
This commit is contained in:
parent
0d30f558f4
commit
3fd4997fc2
22 changed files with 102 additions and 110 deletions
|
@ -55,14 +55,13 @@ ErrorOr<FlatPtr> Process::sys$prctl(int option, FlatPtr arg1, FlatPtr arg2)
|
|||
int user_buffer_size = static_cast<int>(arg2);
|
||||
if (user_buffer_size < 0)
|
||||
return EINVAL;
|
||||
if (user_buffer_size > 256)
|
||||
return ENAMETOOLONG;
|
||||
size_t buffer_size = static_cast<size_t>(user_buffer_size);
|
||||
auto name = TRY(try_copy_kstring_from_user(buffer, buffer_size));
|
||||
Process::Name process_name {};
|
||||
TRY(try_copy_name_from_user_into_fixed_string_buffer<32>(buffer, process_name, buffer_size));
|
||||
// NOTE: Reject empty and whitespace-only names, as they only confuse users.
|
||||
if (name->view().is_whitespace())
|
||||
if (process_name.representable_view().is_whitespace())
|
||||
return EINVAL;
|
||||
set_name(move(name));
|
||||
set_name(process_name.representable_view());
|
||||
return 0;
|
||||
}
|
||||
case PR_GET_PROCESS_NAME: {
|
||||
|
@ -73,9 +72,10 @@ ErrorOr<FlatPtr> Process::sys$prctl(int option, FlatPtr arg1, FlatPtr arg2)
|
|||
return EINVAL;
|
||||
size_t buffer_size = static_cast<size_t>(arg2);
|
||||
TRY(m_name.with([&buffer, buffer_size](auto& name) -> ErrorOr<void> {
|
||||
if (name->length() + 1 > buffer_size)
|
||||
auto view = name.representable_view();
|
||||
if (view.length() + 1 > buffer_size)
|
||||
return ENAMETOOLONG;
|
||||
return copy_to_user(buffer, name->characters(), name->length() + 1);
|
||||
return copy_to_user(buffer, view.characters_without_null_termination(), view.length() + 1);
|
||||
}));
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue