From 386155834910b925daedf25b8d35c14ab655fbaa Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 25 Sep 2009 21:49:16 +0800 Subject: [PATCH] Added sanity check to VFS_GetHandle and fixed CLIShell closing a handle when it still needed to be used --- Kernel/vfs/open.c | 9 +++++++-- Usermode/Applications/CLIShell_src/main.c | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) 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 -- 2.20.1