mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-05 00:56:39 +00:00
AK+Kernel: Introduce StdLib function to copy FixedStringBuffer to user
This new Kernel StdLib function will be used to copy contents of a FixedStringBuffer with a null character to a user process. The first user of this new function is the prctl option of PR_GET_PROCESS_NAME which would copy a process name including a null character to a user provided buffer.
This commit is contained in:
parent
6cb88e224e
commit
72231b405a
Notes:
sideshowbarker
2024-07-17 01:04:03 +09:00
Author: https://github.com/supercomputer7
Commit: 72231b405a
Pull-request: https://github.com/SerenityOS/serenity/pull/20666
Reviewed-by: https://github.com/timschumi ✅
3 changed files with 19 additions and 5 deletions
|
@ -201,3 +201,14 @@ inline ErrorOr<T> copy_typed_from_user(Userspace<T*> user_data)
|
|||
TRY(copy_from_user(&data, user_data));
|
||||
return data;
|
||||
}
|
||||
|
||||
template<size_t Size>
|
||||
ErrorOr<void> copy_fixed_string_buffer_including_null_char_to_user(Userspace<char*> dest, size_t buffer_size, FixedStringBuffer<Size> const& buffer)
|
||||
{
|
||||
FixedStringBuffer<Size + 1> name_with_null_char {};
|
||||
name_with_null_char.store_characters(buffer.representable_view());
|
||||
if (name_with_null_char.stored_length() + 1 > buffer_size)
|
||||
return ENAMETOOLONG;
|
||||
auto name_with_null_char_view = name_with_null_char.span_view_ensuring_ending_null_char();
|
||||
return copy_to_user(dest, name_with_null_char_view.data(), name_with_null_char_view.size());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue