]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
ShellPkg/Ls: Handle the case when SearchString is NULL
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Ls.c
index 34a95835a5a7ee537db4ae4db9427a53932c8e40..9b4c452ca3540b1d4f79adc4856630d09ffb15d1 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Main file for ls shell level 2 function.\r
 \r
-  Copyright (c) 2013 - 2015, Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
+  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -442,6 +442,7 @@ PrintLsOutput(
       }\r
 \r
       if (!Sfo && !HeaderPrinted) {\r
+        PathRemoveLastItem (CorrectedPath);\r
         PrintNonSfoHeader(CorrectedPath);\r
       }\r
       PrintFileInformation(Sfo, Node, &FileCount, &FileSize, &DirCount);\r
@@ -669,6 +670,8 @@ ShellCommandRunLs (
           ASSERT(FullPath == NULL);\r
           StrnCatGrow(&SearchString, NULL, L"*", 0);\r
           StrnCatGrow(&FullPath, NULL, CurDir, 0);\r
+          Size = FullPath != NULL? StrSize(FullPath) : 0;\r
+          StrnCatGrow(&FullPath, &Size, L"\\", 0);\r
         } else {\r
           if (StrStr(PathName, L":") == NULL && gEfiShellProtocol->GetCurDir(NULL) == NULL) {\r
             //\r
@@ -687,6 +690,8 @@ ShellCommandRunLs (
                 ShellCommandLineFreeVarList (Package);\r
                 return SHELL_OUT_OF_RESOURCES;\r
               }\r
+              Size = FullPath != NULL? StrSize(FullPath) : 0;\r
+              StrnCatGrow(&FullPath, &Size, L"\\", 0);\r
             }\r
             StrnCatGrow(&FullPath, &Size, PathName, 0);\r
             if (FullPath == NULL) {\r
@@ -703,10 +708,14 @@ ShellCommandRunLs (
               //\r
               // must split off the search part that applies to files from the end of the directory part\r
               //\r
-              for (StrnCatGrow(&SearchString, NULL, PathName, 0)\r
-                ; SearchString != NULL && StrStr(SearchString, L"\\") != NULL\r
-                ; CopyMem(SearchString, StrStr(SearchString, L"\\") + 1, 1 + StrSize(StrStr(SearchString, L"\\") + 1))) ;\r
-              FullPath[StrLen(FullPath) - StrLen(SearchString)] = CHAR_NULL;\r
+              StrnCatGrow(&SearchString, NULL, FullPath, 0);\r
+              if (SearchString == NULL) {\r
+                FreePool (FullPath);\r
+                ShellCommandLineFreeVarList (Package);\r
+                return SHELL_OUT_OF_RESOURCES;\r
+              }\r
+              PathRemoveLastItem (FullPath);\r
+              CopyMem (SearchString, SearchString + StrLen (FullPath), StrSize (SearchString + StrLen (FullPath)));\r
             }\r
           }\r
         }\r
@@ -725,7 +734,7 @@ ShellCommandRunLs (
             SearchString,\r
             NULL,\r
             Count,\r
-            (INT16)(TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:TheTime.TimeZone)\r
+            TheTime.TimeZone\r
            );\r
           if (ShellStatus == SHELL_NOT_FOUND) {\r
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LS_FILE_NOT_FOUND), gShellLevel2HiiHandle, L"ls", FullPath);  \r