1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

Kernel: Use purpose-sized buffers for holding readlink results

This commit is contained in:
Tim Schumacher 2023-04-16 20:02:28 +02:00 committed by Linus Groh
parent 6f524e35a7
commit f5010f7263

View file

@ -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;
}
}