From 1100f7207b40fef763f353d8a0b4c798253cc2d9 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 10 Sep 2013 08:32:55 +0800 Subject: [PATCH] Modules/Ext2 - Handled zero-sized directory records --- KernelLand/Modules/Filesystems/Ext2/dir.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/KernelLand/Modules/Filesystems/Ext2/dir.c b/KernelLand/Modules/Filesystems/Ext2/dir.c index f04a60cf..3d4d2ad1 100644 --- a/KernelLand/Modules/Filesystems/Ext2/dir.c +++ b/KernelLand/Modules/Filesystems/Ext2/dir.c @@ -68,6 +68,12 @@ int Ext2_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) while(Pos -- && size > 0 && size <= inode->i_size) { VFS_ReadAt( disk->FD, Base+ofs, sizeof(tExt2_DirEnt), &dirent); + + if( dirent.rec_len == 0 ) { + size = 0; + break; + } + ofs += dirent.rec_len; size -= dirent.rec_len; entNum ++; @@ -148,6 +154,8 @@ tVFS_Node *Ext2_FindDir(tVFS_Node *Node, const char *Filename, Uint Flags) // If it matches, create a node and return it if(dirent.name_len == filenameLen && strncmp(dirent.name, Filename, filenameLen) == 0) return Ext2_int_CreateNode( disk, dirent.inode ); + if( dirent.rec_len == 0 ) + break; // Increment pointers ofs += dirent.rec_len; size -= dirent.rec_len; @@ -162,6 +170,8 @@ tVFS_Node *Ext2_FindDir(tVFS_Node *Node, const char *Filename, Uint Flags) } ofs = 0; Base = Ext2_int_GetBlockAddr( disk, inode->i_block, block ); + if( Base == 0 ) + break; } } -- 2.20.1