Added NULL check to VFS_ReadDir
authorJohn Hodge <[email protected]>
Fri, 25 Sep 2009 12:46:42 +0000 (20:46 +0800)
committerJohn Hodge <[email protected]>
Fri, 25 Sep 2009 12:46:42 +0000 (20:46 +0800)
Kernel/vfs/dir.c
Usermode/Applications/CLIShell_src/main.c

index d3214a4..ba2311e 100644 (file)
@@ -159,7 +159,7 @@ int VFS_ReadDir(int FD, char *Dest)
                        h->Position += (Uint)tmp;
                else
                        h->Position ++;
-       } while((Uint)tmp < (Uint)VFS_MAXSKIP);
+       } while(tmp != NULL && (Uint)tmp < (Uint)VFS_MAXSKIP);
        LOG("tmp = '%s'", tmp);
        
        if(!tmp) {
index 494b25e..30cf288 100644 (file)
@@ -335,7 +335,7 @@ void Command_Dir(int argc, char **argv)
         int    dp, fp, dirLen;\r
        //char  modeStr[11] = "RWXrwxRWX ";\r
        char    tmpPath[1024];\r
-       char    fileName[256];\r
+       char    *fileName;\r
        t_sysFInfo      info;\r
        \r
        // Generate Directory Path\r
@@ -381,6 +381,8 @@ void Command_Dir(int argc, char **argv)
                tmpPath[dirLen++] = '/';\r
                tmpPath[dirLen] = '\0';\r
        }\r
+       \r
+       fileName = (char*)(tmpPath+dirLen);\r
        // Read Directory Content\r
        while( (fp = readdir(dp, fileName)) )\r
        {\r
@@ -390,8 +392,6 @@ void Command_Dir(int argc, char **argv)
                                write(_stdout, 42, "Invalid Permissions to traverse directory\n");\r
                        break;\r
                }\r
-               // Create File Path\r
-               strcpy((char*)(tmpPath+dirLen), fileName);\r
                // Open File\r
                fp = open(tmpPath, 0);\r
                if(fp == -1)    continue;\r
@@ -400,9 +400,10 @@ void Command_Dir(int argc, char **argv)
                close(fp);\r
                \r
                // Colour Code\r
-               write(_stdout, 6, "\x1B[37m");  //White\r
-               if(info.flags & FILEFLAG_DIRECTORY)     //Directory Green\r
+               if(info.flags & FILEFLAG_DIRECTORY)     // Directory: Green\r
                        write(_stdout, 6, "\x1B[32m");\r
+               else\r
+                       write(_stdout, 6, "\x1B[37m");  // Default: White\r
                \r
                //Print Mode\r
                #if 0\r
@@ -418,15 +419,15 @@ void Command_Dir(int argc, char **argv)
                write(_stdout, 10, modeStr);\r
                #endif\r
                \r
-               //Print Name\r
+               // Print Name\r
                write(_stdout, strlen(fileName), fileName);\r
-               //Print slash if applicable\r
+               // Print slash if applicable\r
                if(info.flags & FILEFLAG_DIRECTORY)\r
                        write(_stdout, 1, "/");\r
                \r
-               // Revert Colout and end line\r
+               // Revert Colour and end line\r
                write(_stdout, 6, "\x1B[37m");\r
-               write(_stdout, 2, "\n");\r
+               write(_stdout, 1, "\n");\r
        }\r
        // Close Directory\r
        close(dp);\r

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