Kernel/FileSystem: Add check of read offset for the FATInode code

Apparently we lacked this important check from the beginning of this
piece of code. This check is crucial to ensure we only give back data
being related to the FATInode data buffer and nothing beyond it.
This commit is contained in:
Liav A 2023-02-18 16:44:16 +02:00 committed by Andreas Kling
parent 6cc5e09c71
commit 9790b81959
Notes: sideshowbarker 2024-07-17 08:37:36 +09:00

View file

@ -201,6 +201,9 @@ u32 FATInode::first_cluster() const
ErrorOr<size_t> FATInode::read_bytes_locked(off_t offset, size_t size, UserOrKernelBuffer& buffer, OpenFileDescription*) const
{
dbgln_if(FAT_DEBUG, "FATFS: Reading inode {}: size: {} offset: {}", identifier().index(), size, offset);
VERIFY(offset >= 0);
if (offset >= m_metadata.size)
return 0;
// FIXME: Read only the needed blocks instead of the whole file
auto blocks = TRY(const_cast<FATInode&>(*this).read_block_list());