From 584e23abe1d64427e584533529ab1a81590293ae Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 10 Oct 2009 09:53:33 +0800 Subject: [PATCH] Fixed Infinite reading in ext2 driver, removed debug from DrvUitl --- Kernel/vfs/fs/ext2.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Kernel/vfs/fs/ext2.c b/Kernel/vfs/fs/ext2.c index 1da9c0f8..0c4b527b 100644 --- a/Kernel/vfs/fs/ext2.c +++ b/Kernel/vfs/fs/ext2.c @@ -201,9 +201,22 @@ Uint64 Ext2_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) // Get Inode Ext2_int_GetInode(Node, &inode); + // Sanity Checks + if(Offset >= inode.i_size) { + LEAVE('i', 0); + return 0; + } + if(Offset + Length > inode.i_size) + Length = inode.i_size - Offset; + block = Offset / disk->BlockSize; Offset = Offset / disk->BlockSize; base = Ext2_int_GetBlockAddr(disk, inode.i_block, block); + if(base == 0) { + Warning("[EXT2 ] NULL Block Detected in INode 0x%llx\n", Node->Inode); + LEAVE('i', 0); + return 0; + } // Read only block if(Length <= disk->BlockSize - Offset) @@ -224,6 +237,11 @@ Uint64 Ext2_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) while(remLen > disk->BlockSize) { base = Ext2_int_GetBlockAddr(disk, inode.i_block, block); + if(base == 0) { + Warning("[EXT2 ] NULL Block Detected in INode 0x%llx\n", Node->Inode); + LEAVE('i', 0); + return 0; + } VFS_ReadAt( disk->FD, base, disk->BlockSize, Buffer); Buffer += disk->BlockSize; remLen -= disk->BlockSize; -- 2.20.1