Added sanity check to VFS_GetHandle and fixed CLIShell closing a handle when it still...
authorJohn Hodge <[email protected]>
Fri, 25 Sep 2009 13:49:16 +0000 (21:49 +0800)
committerJohn Hodge <[email protected]>
Fri, 25 Sep 2009 13:49:16 +0000 (21:49 +0800)
Kernel/vfs/open.c
Usermode/Applications/CLIShell_src/main.c

index fa5fe66..64c65db 100644 (file)
@@ -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;
 }
index 04acc14..f4d703c 100644 (file)
@@ -397,7 +397,6 @@ void Command_Dir(int argc, char **argv)
                if(fp == -1)    continue;\r
                // Get File Stats\r
                finfo(fp, &info, 0);\r
-               close(fp);\r
                \r
                //Print Mode\r
                //#if 0\r
@@ -418,6 +417,7 @@ void Command_Dir(int argc, char **argv)
                if(acl.perms & 1)       modeStr[8] = 'x';       else    modeStr[8] = '-';\r
                write(_stdout, 10, modeStr);\r
                //#endif\r
+               close(fp);\r
                \r
                // Colour Code\r
                if(info.flags & FILEFLAG_DIRECTORY)     // Directory: Green\r

UCC git Repository :: git.ucc.asn.au