mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
Kernel+LibC: Do not return -ENAMETOOLONG from sys$readlink()
That's not how readlink() is supposed to work: it should copy as many bytes as fit into the buffer, and return the number of bytes copied. So do that, but add a twist: make sys$readlink() actually return the whole size, not the number of bytes copied. We fix up this return value in userspace, to make LibC's readlink() behave as expected, but this will also allow other code to allocate a buffer of just the right size. Also, avoid an extra copy of the link target.
This commit is contained in:
parent
35329400b8
commit
47d83800e1
Notes:
sideshowbarker
2024-07-19 05:36:57 +09:00
Author: https://github.com/bugaevc
Commit: 47d83800e1
Pull-request: https://github.com/SerenityOS/serenity/pull/2564
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/awesomekling
2 changed files with 7 additions and 6 deletions
|
@ -1953,11 +1953,11 @@ int Process::sys$readlink(const Syscall::SC_readlink_params* user_params)
|
|||
if (contents.is_error())
|
||||
return contents.error();
|
||||
|
||||
auto link_target = String::copy(contents.value());
|
||||
if (link_target.length() > params.buffer.size)
|
||||
return -ENAMETOOLONG;
|
||||
copy_to_user(params.buffer.data, link_target.characters(), link_target.length());
|
||||
return link_target.length();
|
||||
auto& link_target = contents.value();
|
||||
auto size_to_copy = min(link_target.size(), params.buffer.size);
|
||||
copy_to_user(params.buffer.data, link_target.data(), size_to_copy);
|
||||
// Note: we return the whole size here, not the copied size.
|
||||
return link_target.size();
|
||||
}
|
||||
|
||||
int Process::sys$chdir(const char* user_path, size_t path_length)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue