mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:07:46 +00:00
Kernel: Use purpose-sized buffers for holding readlink results
This commit is contained in:
parent
6f524e35a7
commit
f5010f7263
1 changed files with 9 additions and 4 deletions
|
@ -22,11 +22,16 @@ ErrorOr<FlatPtr> Process::sys$readlink(Userspace<Syscall::SC_readlink_params con
|
|||
if (!description->metadata().is_symlink())
|
||||
return EINVAL;
|
||||
|
||||
auto link_target = TRY(description->read_entire_file());
|
||||
auto size_to_copy = min(link_target->size(), params.buffer.size);
|
||||
TRY(copy_to_user(params.buffer.data, link_target->data(), size_to_copy));
|
||||
// Make sure that our assumptions about the path length hold up.
|
||||
// Note that this doesn't mean that the reported size can be trusted, some inodes just report zero.
|
||||
VERIFY(description->inode()->size() <= MAXPATHLEN);
|
||||
|
||||
Array<u8, MAXPATHLEN> link_target;
|
||||
auto read_bytes = TRY(description->inode()->read_until_filled_or_end(0, link_target.size(), UserOrKernelBuffer::for_kernel_buffer(link_target.data()), description));
|
||||
auto size_to_copy = min(read_bytes, params.buffer.size);
|
||||
TRY(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();
|
||||
return read_bytes;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue