Add code to check whether the pointer 'CorrectedPath' and 'FullPath' are NULL before...
authorShumin Qiu <shumin.qiu@intel.com>
Tue, 25 Feb 2014 08:30:32 +0000 (08:30 +0000)
committershenshushi <shenshushi@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 25 Feb 2014 08:30:32 +0000 (08:30 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Shumin Qiu <shumin.qiu@intel.com>
Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15260 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c

index b5ef6aa2a9fbce870ad8a24ade61bf7121f50a14..63af5eab18884d216110df720440073607260719 100644 (file)
@@ -379,6 +379,9 @@ PrintLsOutput(
   }\r
 \r
   CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, RootPath,     0);\r
   }\r
 \r
   CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, RootPath,     0);\r
+  if (CorrectedPath == NULL) {\r
+    return SHELL_OUT_OF_RESOURCES;\r
+  }\r
   if (CorrectedPath[StrLen(CorrectedPath)-1] != L'\\'\r
     &&CorrectedPath[StrLen(CorrectedPath)-1] != L'/') {\r
     CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, L"\\",     0);\r
   if (CorrectedPath[StrLen(CorrectedPath)-1] != L'\\'\r
     &&CorrectedPath[StrLen(CorrectedPath)-1] != L'/') {\r
     CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, L"\\",     0);\r
@@ -666,8 +669,17 @@ ShellCommandRunLs (
             ASSERT((FullPath == NULL && Size == 0) || (FullPath != NULL));\r
             if (StrStr(PathName, L":") == NULL) {\r
               StrnCatGrow(&FullPath, &Size, gEfiShellProtocol->GetCurDir(NULL), 0);\r
             ASSERT((FullPath == NULL && Size == 0) || (FullPath != NULL));\r
             if (StrStr(PathName, L":") == NULL) {\r
               StrnCatGrow(&FullPath, &Size, gEfiShellProtocol->GetCurDir(NULL), 0);\r
+              if (FullPath == NULL) {\r
+                ShellCommandLineFreeVarList (Package);\r
+                return SHELL_OUT_OF_RESOURCES;\r
+              }\r
             }\r
             StrnCatGrow(&FullPath, &Size, PathName, 0);\r
             }\r
             StrnCatGrow(&FullPath, &Size, PathName, 0);\r
+            if (FullPath == NULL) {\r
+                ShellCommandLineFreeVarList (Package);\r
+                return SHELL_OUT_OF_RESOURCES;\r
+            }\r
+               \r
             if  (ShellIsDirectory(PathName) == EFI_SUCCESS) {\r
               //\r
               // is listing ends with a directory, then we list all files in that directory\r
             if  (ShellIsDirectory(PathName) == EFI_SUCCESS) {\r
               //\r
               // is listing ends with a directory, then we list all files in that directory\r