From: John Hodge Date: Fri, 25 Sep 2009 13:49:16 +0000 (+0800) Subject: Added sanity check to VFS_GetHandle and fixed CLIShell closing a handle when it still... X-Git-Tag: rel0.06~501 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=386155834910b925daedf25b8d35c14ab655fbaa;p=tpg%2Facess2.git Added sanity check to VFS_GetHandle and fixed CLIShell closing a handle when it still needed to be used --- diff --git a/Kernel/vfs/open.c b/Kernel/vfs/open.c index fa5fe66f..64c65dbc 100644 --- a/Kernel/vfs/open.c +++ b/Kernel/vfs/open.c @@ -501,14 +501,19 @@ void VFS_Close(int FD) */ tVFS_Handle *VFS_GetHandle(int FD) { + tVFS_Handle *h; + if(FD < 0) return NULL; if(FD & VFS_KERNEL_FLAG) { FD &= (VFS_KERNEL_FLAG - 1); if(FD >= MAX_KERNEL_FILES) return NULL; - return &gaKernelHandles[ FD ]; + h = &gaKernelHandles[ FD ]; } else { if(FD >= CFGINT(CFG_VFS_MAXFILES)) return NULL; - return &gaUserHandles[ FD ]; + h = &gaUserHandles[ FD ]; } + + if(h->Node == NULL) return NULL; + return h; } diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index 04acc141..f4d703cf 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -397,7 +397,6 @@ void Command_Dir(int argc, char **argv) if(fp == -1) continue; // Get File Stats finfo(fp, &info, 0); - close(fp); //Print Mode //#if 0 @@ -418,6 +417,7 @@ void Command_Dir(int argc, char **argv) if(acl.perms & 1) modeStr[8] = 'x'; else modeStr[8] = '-'; write(_stdout, 10, modeStr); //#endif + close(fp); // Colour Code if(info.flags & FILEFLAG_DIRECTORY) // Directory: Green