mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 15:16:14 +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:
committed by
Andreas Kling
parent
35329400b8
commit
47d83800e1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user