ShellPkg: Add checking for memory allocation and pointer returns from functions.
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 14 Oct 2011 19:21:13 +0000 (19:21 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 14 Oct 2011 19:21:13 +0000 (19:21 +0000)
signed-off-by: jcarsey
reviewed-by: geekboy15a

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12540 6f19259b-4bc3-4df7-8a09-765794883524

15 files changed:
ShellPkg/Application/Shell/Shell.c
ShellPkg/Application/Shell/ShellManParser.c
ShellPkg/Application/Shell/ShellParametersProtocol.c
ShellPkg/Application/Shell/ShellProtocol.c
ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c
ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c
ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c
ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
ShellPkg/Library/UefiShellLevel1CommandsLib/If.c
ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c
ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c

index 614c1e9..d266c82 100644 (file)
@@ -857,15 +857,19 @@ DoStartupScript(
     FileStringPath = NULL;\r
     NewSize = 0;\r
     FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, MapName, 0);\r
-    TempSpot = StrStr(FileStringPath, L";");\r
-    if (TempSpot != NULL) {\r
-      *TempSpot = CHAR_NULL;\r
+    if (FileStringPath == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+    } else {\r
+      TempSpot = StrStr(FileStringPath, L";");\r
+      if (TempSpot != NULL) {\r
+        *TempSpot = CHAR_NULL;\r
+      }\r
+      FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH_DEVICE_PATH*)FilePath)->PathName, 0);\r
+      PathRemoveLastItem(FileStringPath);\r
+      FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0);\r
+      Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ);\r
+      FreePool(FileStringPath);\r
     }\r
-    FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH_DEVICE_PATH*)FilePath)->PathName, 0);\r
-    PathRemoveLastItem(FileStringPath);\r
-    FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0);\r
-    Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ);\r
-    FreePool(FileStringPath);\r
   }\r
   if (EFI_ERROR(Status)) {\r
     NamePath = FileDevicePath (NULL, mStartupScript);\r
@@ -1215,6 +1219,12 @@ RunSplitCommand(
 \r
   NextCommandLine = StrnCatGrow(&NextCommandLine, &Size1, StrStr(CmdLine, L"|")+1, 0);\r
   OurCommandLine  = StrnCatGrow(&OurCommandLine , &Size2, CmdLine                , StrStr(CmdLine, L"|") - CmdLine);\r
+\r
+  if (NextCommandLine == NULL || OurCommandLine == NULL) {\r
+    SHELL_FREE_NON_NULL(OurCommandLine);\r
+    SHELL_FREE_NON_NULL(NextCommandLine);\r
+    return (EFI_OUT_OF_RESOURCES);\r
+  }\r
   if (NextCommandLine[0] != CHAR_NULL &&\r
       NextCommandLine[0] == L'a' &&\r
       NextCommandLine[1] == L' '\r
@@ -1334,6 +1344,9 @@ RunCommand(
   Split               = NULL;\r
 \r
   CleanOriginal = StrnCatGrow(&CleanOriginal, NULL, CmdLine, 0);\r
+  if (CleanOriginal == NULL) {\r
+    return (EFI_OUT_OF_RESOURCES);\r
+  }\r
   while (CleanOriginal[StrLen(CleanOriginal)-1] == L' ') {\r
     CleanOriginal[StrLen(CleanOriginal)-1] = CHAR_NULL;\r
   }\r
index bd2efcb..470f51a 100644 (file)
@@ -180,6 +180,10 @@ ManBufferFindSections(
         TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\n"));\r
         ASSERT(TempString == NULL);\r
         TempString = StrnCatGrow(&TempString, NULL, CurrentLocation, TempString2==NULL?0:TempString2 - CurrentLocation);\r
+        if (TempString == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          break;\r
+        }\r
         SectionName = TempString;\r
         SectionLen = StrLen(SectionName);\r
         SectionName = StrStr(Sections, SectionName);\r
@@ -197,12 +201,24 @@ ManBufferFindSections(
         TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\n"));\r
         ASSERT(TempString == NULL);\r
         TempString = StrnCatGrow(&TempString, NULL, CurrentLocation, TempString2==NULL?0:TempString2 - CurrentLocation);\r
+        if (TempString == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          break;\r
+        }\r
         //\r
         // copy and save the current line.\r
         //\r
         ASSERT((*HelpText == NULL && *HelpSize == 0) || (*HelpText != NULL));\r
         StrnCatGrow (HelpText, HelpSize, TempString, 0);\r
+        if (HelpText == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          break;\r
+        }\r
         StrnCatGrow (HelpText, HelpSize, L"\r\n", 0);\r
+        if (HelpText == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          break;\r
+        }\r
       }\r
     }\r
     SHELL_FREE_NON_NULL(TempString);\r
index 5beaada..55cf3c2 100644 (file)
@@ -577,6 +577,9 @@ UpdateStdInStdOutStdErr(
   }\r
 \r
   CommandLineCopy = StrnCatGrow(&CommandLineCopy, NULL, NewCommandLine, 0);\r
+  if (CommandLineCopy == NULL) {\r
+    return (EFI_OUT_OF_RESOURCES);\r
+  }\r
   Status          = EFI_SUCCESS;\r
   Split           = NULL;\r
   FirstLocation   = CommandLineCopy + StrLen(CommandLineCopy);\r
@@ -1030,16 +1033,19 @@ UpdateStdInStdOutStdErr(
       //\r
       if (!EFI_ERROR(Status) && StdInVarName != NULL) {\r
         TempHandle = CreateFileInterfaceEnv(StdInVarName);\r
-        if (!InUnicode) {\r
-          TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);\r
-        }\r
-        Size = 0;\r
-        ASSERT(TempHandle != NULL);\r
-        if (((EFI_FILE_PROTOCOL*)TempHandle)->Read(TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL) {\r
-          Status = EFI_INVALID_PARAMETER;\r
+        if (TempHandle == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
         } else {\r
-          ShellParameters->StdIn = TempHandle;\r
-          gST->ConIn = CreateSimpleTextInOnFile(TempHandle, &gST->ConsoleInHandle);\r
+          if (!InUnicode) {\r
+            TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);\r
+          }\r
+          Size = 0;\r
+          if (((EFI_FILE_PROTOCOL*)TempHandle)->Read(TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL) {\r
+            Status = EFI_INVALID_PARAMETER;\r
+          } else {\r
+            ShellParameters->StdIn = TempHandle;\r
+            gST->ConIn = CreateSimpleTextInOnFile(TempHandle, &gST->ConsoleInHandle);\r
+          }\r
         }\r
       }\r
 \r
index de7dc3c..6b81918 100644 (file)
@@ -488,10 +488,12 @@ EfiShellGetFilePathFromDevicePath(
   This function converts a file system style name to a device path, by replacing any\r
   mapping references to the associated device path.\r
 \r
-  @param Path                   the pointer to the path\r
+  @param[in] Path               The pointer to the path.\r
 \r
-  @return all                   The pointer of the file path. The file path is callee\r
+  @return                       The pointer of the file path. The file path is callee\r
                                 allocated and should be freed by the caller.\r
+  @retval NULL                  The path could not be found.\r
+  @retval NULL                  There was not enough available memory.\r
 **/\r
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
@@ -525,7 +527,9 @@ EfiShellGetDevicePathFromFilePath(
     Size = StrSize(Cwd);\r
     Size += StrSize(Path);\r
     NewPath = AllocateZeroPool(Size);\r
-    ASSERT(NewPath != NULL);\r
+    if (NewPath == NULL) {\r
+      return (NULL);\r
+    }\r
     StrCpy(NewPath, Cwd);\r
     if (*Path == L'\\') {\r
       Path++;\r
@@ -543,8 +547,7 @@ EfiShellGetDevicePathFromFilePath(
   //\r
   ASSERT((MapName == NULL && Size == 0) || (MapName != NULL));\r
   MapName = StrnCatGrow(&MapName, &Size, Path, (StrStr(Path, L":")-Path+1));\r
-  if (MapName[StrLen(MapName)-1] != L':') {\r
-    ASSERT(FALSE);\r
+  if (MapName == NULL || MapName[StrLen(MapName)-1] != L':') {\r
     return (NULL);\r
   }\r
 \r
@@ -564,7 +567,6 @@ EfiShellGetDevicePathFromFilePath(
   //\r
   DevicePathCopyForFree = DevicePathCopy = DuplicateDevicePath(DevicePath);\r
   if (DevicePathCopy == NULL) {\r
-    ASSERT(FALSE);\r
     FreePool(MapName);\r
     return (NULL);\r
   }\r
@@ -1888,6 +1890,9 @@ EfiShellFindFilesInDir(
     TempString        = NULL;\r
     Size              = 0;\r
     TempString        = StrnCatGrow(&TempString, &Size, ShellFileHandleGetPath(FileDirHandle), 0);\r
+    if (TempString == NULL) {\r
+      return (EFI_OUT_OF_RESOURCES);\r
+    }\r
     TempSpot          = StrStr(TempString, L";");\r
 \r
     if (TempSpot != NULL) {\r
@@ -1895,6 +1900,9 @@ EfiShellFindFilesInDir(
     }\r
 \r
     TempString        = StrnCatGrow(&TempString, &Size, BasePath, 0);\r
+    if (TempString == NULL) {\r
+      return (EFI_OUT_OF_RESOURCES);\r
+    }\r
     BasePath          = TempString;\r
   }\r
 \r
@@ -2239,6 +2247,9 @@ EfiShellFindFiles(
 \r
   ASSERT(MapName == NULL);\r
   MapName = StrnCatGrow(&MapName, NULL, PatternCopy, Count);\r
+  if (MapName == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+  }\r
 \r
   if (!EFI_ERROR(Status)) {\r
     RootDevicePath = EfiShellGetDevicePathFromFilePath(PatternCopy);\r
@@ -2759,7 +2770,7 @@ EfiShellSetCurDir(
       MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0);\r
       ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r
       MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, DirectoryName, 0);\r
-      if (MapListItem->CurrentDirectoryPath[StrLen(MapListItem->CurrentDirectoryPath)-1] != L'\\') {\r
+      if (MapListItem->CurrentDirectoryPath != NULL && MapListItem->CurrentDirectoryPath[StrLen(MapListItem->CurrentDirectoryPath)-1] != L'\\') {\r
         ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r
         MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0);\r
       }\r
index de2ce2b..ffd05b8 100644 (file)
@@ -978,7 +978,7 @@ ShellCommandRunBcfg (
           ShellStatus = BcfgAddDebug1(\r
             CurrentOperation.Number1,\r
             CurrentOperation.FileName,\r
-            CurrentOperation.Description,\r
+            CurrentOperation.Description==NULL?L"":CurrentOperation.Description,\r
             CurrentOperation.Order,\r
             Length / sizeof(CurrentOperation.Order[0]),\r
             CurrentOperation.Target,\r
index f5fb7d2..ff3819c 100644 (file)
@@ -178,6 +178,7 @@ HFileImageRead (
 \r
     StatusBarSetStatusString (UnicodeBuffer);\r
     FreePool (UnicodeBuffer);\r
+    return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
   HFileImageSetFileName (FileName);\r
index 9ab5d89..945002a 100644 (file)
@@ -303,6 +303,9 @@ ConvertStringToGuid (
   } \r
   TempCopy = NULL;\r
   TempCopy = StrnCatGrow(&TempCopy, NULL, StringGuid, 0);\r
+  if (TempCopy == NULL) {\r
+    return (EFI_OUT_OF_RESOURCES);\r
+  }\r
   Walker   = TempCopy;\r
   TempSpot = StrStr(Walker, L"-");\r
   if (TempSpot != NULL) {\r
index 01f04a5..ed13dba 100644 (file)
@@ -978,7 +978,7 @@ ShellCommandRunBcfgInstall (
           ShellStatus = BcfgAddInstall1(\r
             CurrentOperation.Number1,\r
             CurrentOperation.FileName,\r
-            CurrentOperation.Description,\r
+            CurrentOperation.Description==NULL?L"":CurrentOperation.Description,\r
             CurrentOperation.Order,\r
             Length / sizeof(CurrentOperation.Order[0]),\r
             CurrentOperation.Target,\r
index 4a85708..121ac50 100644 (file)
@@ -376,29 +376,33 @@ ShellCommandRunFor (
         }\r
         ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);\r
       }\r
-      //\r
-      // set up for an 'in' for loop\r
-      //\r
-      NewSize = StrSize(ArgSet);\r
-      NewSize += sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]);\r
-      Info = AllocateZeroPool(NewSize);\r
-      ASSERT(Info != NULL);\r
-      Info->Signature = SHELL_FOR_INFO_SIGNATURE;\r
-      CopyMem(Info->Set, ArgSet, StrSize(ArgSet));\r
-      NewSize = StrSize(gEfiShellParametersProtocol->Argv[1]);\r
-      CopyMem(Info->Set+(StrSize(ArgSet)/sizeof(Info->Set[0])), gEfiShellParametersProtocol->Argv[1], NewSize);\r
-      Info->ReplacementName = Info->Set+StrSize(ArgSet)/sizeof(Info->Set[0]);\r
-      Info->CurrentValue  = (CHAR16*)Info->Set;\r
-      Info->Step          = 0;\r
-      Info->Current       = 0;\r
-      Info->End           = 0;\r
-\r
-      if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {\r
-        Info->RemoveSubstAlias  = FALSE;\r
+      if (ArgSet == NULL) {\r
+        ShellStatus = SHELL_OUT_OF_RESOURCES;\r
       } else {\r
-        Info->RemoveSubstAlias  = TRUE;\r
+        //\r
+        // set up for an 'in' for loop\r
+        //\r
+        NewSize = StrSize(ArgSet);\r
+        NewSize += sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]);\r
+        Info = AllocateZeroPool(NewSize);\r
+        ASSERT(Info != NULL);\r
+        Info->Signature = SHELL_FOR_INFO_SIGNATURE;\r
+        CopyMem(Info->Set, ArgSet, StrSize(ArgSet));\r
+        NewSize = StrSize(gEfiShellParametersProtocol->Argv[1]);\r
+        CopyMem(Info->Set+(StrSize(ArgSet)/sizeof(Info->Set[0])), gEfiShellParametersProtocol->Argv[1], NewSize);\r
+        Info->ReplacementName = Info->Set+StrSize(ArgSet)/sizeof(Info->Set[0]);\r
+        Info->CurrentValue  = (CHAR16*)Info->Set;\r
+        Info->Step          = 0;\r
+        Info->Current       = 0;\r
+        Info->End           = 0;\r
+\r
+        if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {\r
+          Info->RemoveSubstAlias  = FALSE;\r
+        } else {\r
+          Info->RemoveSubstAlias  = TRUE;\r
+        }\r
+        CurrentScriptFile->CurrentCommand->Data = Info;\r
       }\r
-      CurrentScriptFile->CurrentCommand->Data = Info;\r
     } else if (gUnicodeCollation->StriColl(\r
         gUnicodeCollation,\r
         L"run",\r
@@ -413,80 +417,61 @@ ShellCommandRunFor (
         ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);\r
 //        ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);\r
       }\r
-      //\r
-      // set up for a 'run' for loop\r
-      //\r
-      Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]));\r
-      ASSERT(Info != NULL);\r
-      CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1]));\r
-      Info->ReplacementName = Info->Set;\r
-      Info->CurrentValue    = NULL;\r
-      ArgSetWalker            = ArgSet;\r
-      if (ArgSetWalker[0] != L'(') {\r
-        ShellPrintHiiEx(\r
-          -1, \r
-          -1, \r
-          NULL, \r
-          STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r
-          gShellLevel1HiiHandle, \r
-          ArgSet, \r
-          CurrentScriptFile!=NULL \r
-            && CurrentScriptFile->CurrentCommand!=NULL\r
-            ? CurrentScriptFile->CurrentCommand->Line:0);\r
-        ShellStatus = SHELL_INVALID_PARAMETER;\r
+      if (ArgSet == NULL) {\r
+        ShellStatus = SHELL_OUT_OF_RESOURCES;\r
       } else {\r
-        TempSpot = StrStr(ArgSetWalker, L")");\r
-        if (TempSpot != NULL) {\r
-          TempString = TempSpot+1;\r
-          if (*(TempString) != CHAR_NULL) {\r
-            while(TempString != NULL && *TempString == L' ') {\r
-              TempString++;\r
-            }\r
-            if (StrLen(TempString) > 0) {\r
-              TempSpot = NULL;\r
-            }\r
-          }\r
-        }\r
-        if (TempSpot == NULL) {\r
+        //\r
+        // set up for a 'run' for loop\r
+        //\r
+        Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]));\r
+        ASSERT(Info != NULL);\r
+        CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1]));\r
+        Info->ReplacementName = Info->Set;\r
+        Info->CurrentValue    = NULL;\r
+        ArgSetWalker            = ArgSet;\r
+        if (ArgSetWalker[0] != L'(') {\r
           ShellPrintHiiEx(\r
             -1, \r
             -1, \r
             NULL, \r
             STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r
             gShellLevel1HiiHandle, \r
+            ArgSet, \r
             CurrentScriptFile!=NULL \r
               && CurrentScriptFile->CurrentCommand!=NULL\r
               ? CurrentScriptFile->CurrentCommand->Line:0);\r
           ShellStatus = SHELL_INVALID_PARAMETER;\r
         } else {\r
-          *TempSpot = CHAR_NULL;\r
-          ArgSetWalker++;\r
-          while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {\r
-            ArgSetWalker++;\r
+          TempSpot = StrStr(ArgSetWalker, L")");\r
+          if (TempSpot != NULL) {\r
+            TempString = TempSpot+1;\r
+            if (*(TempString) != CHAR_NULL) {\r
+              while(TempString != NULL && *TempString == L' ') {\r
+                TempString++;\r
+              }\r
+              if (StrLen(TempString) > 0) {\r
+                TempSpot = NULL;\r
+              }\r
+            }\r
           }\r
-          if (!ShellIsValidForNumber(ArgSetWalker)) {\r
+          if (TempSpot == NULL) {\r
             ShellPrintHiiEx(\r
               -1, \r
               -1, \r
               NULL, \r
               STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r
               gShellLevel1HiiHandle, \r
-              ArgSet, \r
               CurrentScriptFile!=NULL \r
                 && CurrentScriptFile->CurrentCommand!=NULL\r
                 ? CurrentScriptFile->CurrentCommand->Line:0);\r
             ShellStatus = SHELL_INVALID_PARAMETER;\r
           } else {\r
-            if (ArgSetWalker[0] == L'-') {\r
-              Info->Current = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);\r
-            } else {\r
-              Info->Current = (INTN)ShellStrToUintn(ArgSetWalker);\r
-            }\r
-            ArgSetWalker  = StrStr(ArgSetWalker, L" ");\r
+            *TempSpot = CHAR_NULL;\r
+            ArgSetWalker++;\r
             while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {\r
               ArgSetWalker++;\r
             }\r
-            if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){\r
+            if (!ShellIsValidForNumber(ArgSetWalker)) {\r
               ShellPrintHiiEx(\r
                 -1, \r
                 -1, \r
@@ -500,73 +485,96 @@ ShellCommandRunFor (
               ShellStatus = SHELL_INVALID_PARAMETER;\r
             } else {\r
               if (ArgSetWalker[0] == L'-') {\r
-                Info->End = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);\r
-              } else {\r
-                Info->End = (INTN)ShellStrToUintn(ArgSetWalker);\r
-              }\r
-              if (Info->Current < Info->End) {\r
-                Info->Step            = 1;\r
+                Info->Current = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);\r
               } else {\r
-                Info->Step            = -1;\r
+                Info->Current = (INTN)ShellStrToUintn(ArgSetWalker);\r
               }\r
-\r
               ArgSetWalker  = StrStr(ArgSetWalker, L" ");\r
               while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {\r
                 ArgSetWalker++;\r
               }\r
-              if (ArgSetWalker != NULL && *ArgSetWalker != CHAR_NULL) {\r
-                if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){\r
-                  ShellPrintHiiEx(\r
-                    -1, \r
-                    -1, \r
-                    NULL, \r
-                    STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r
-                    gShellLevel1HiiHandle, \r
-                    ArgSet, \r
-                    CurrentScriptFile!=NULL \r
-                      && CurrentScriptFile->CurrentCommand!=NULL\r
-                      ? CurrentScriptFile->CurrentCommand->Line:0);\r
-                  ShellStatus = SHELL_INVALID_PARAMETER;\r
+              if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){\r
+                ShellPrintHiiEx(\r
+                  -1, \r
+                  -1, \r
+                  NULL, \r
+                  STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r
+                  gShellLevel1HiiHandle, \r
+                  ArgSet, \r
+                  CurrentScriptFile!=NULL \r
+                    && CurrentScriptFile->CurrentCommand!=NULL\r
+                    ? CurrentScriptFile->CurrentCommand->Line:0);\r
+                ShellStatus = SHELL_INVALID_PARAMETER;\r
+              } else {\r
+                if (ArgSetWalker[0] == L'-') {\r
+                  Info->End = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);\r
                 } else {\r
-                  if (*ArgSetWalker == L')') {\r
-                    ASSERT(Info->Step == 1 || Info->Step == -1);\r
+                  Info->End = (INTN)ShellStrToUintn(ArgSetWalker);\r
+                }\r
+                if (Info->Current < Info->End) {\r
+                  Info->Step            = 1;\r
+                } else {\r
+                  Info->Step            = -1;\r
+                }\r
+\r
+                ArgSetWalker  = StrStr(ArgSetWalker, L" ");\r
+                while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {\r
+                  ArgSetWalker++;\r
+                }\r
+                if (ArgSetWalker != NULL && *ArgSetWalker != CHAR_NULL) {\r
+                  if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){\r
+                    ShellPrintHiiEx(\r
+                      -1, \r
+                      -1, \r
+                      NULL, \r
+                      STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r
+                      gShellLevel1HiiHandle, \r
+                      ArgSet, \r
+                      CurrentScriptFile!=NULL \r
+                        && CurrentScriptFile->CurrentCommand!=NULL\r
+                        ? CurrentScriptFile->CurrentCommand->Line:0);\r
+                    ShellStatus = SHELL_INVALID_PARAMETER;\r
                   } else {\r
-                    if (ArgSetWalker[0] == L'-') {\r
-                      Info->Step = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);\r
+                    if (*ArgSetWalker == L')') {\r
+                      ASSERT(Info->Step == 1 || Info->Step == -1);\r
                     } else {\r
-                      Info->Step = (INTN)ShellStrToUintn(ArgSetWalker);\r
-                    }\r
-\r
-                    if (StrStr(ArgSetWalker, L" ") != NULL) {\r
-                      ShellPrintHiiEx(\r
-                        -1, \r
-                        -1, \r
-                        NULL, \r
-                        STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r
-                        gShellLevel1HiiHandle, \r
-                        ArgSet, \r
-                        CurrentScriptFile!=NULL \r
-                          && CurrentScriptFile->CurrentCommand!=NULL\r
-                          ? CurrentScriptFile->CurrentCommand->Line:0);\r
-                      ShellStatus = SHELL_INVALID_PARAMETER;\r
+                      if (ArgSetWalker[0] == L'-') {\r
+                        Info->Step = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);\r
+                      } else {\r
+                        Info->Step = (INTN)ShellStrToUintn(ArgSetWalker);\r
+                      }\r
+\r
+                      if (StrStr(ArgSetWalker, L" ") != NULL) {\r
+                        ShellPrintHiiEx(\r
+                          -1, \r
+                          -1, \r
+                          NULL, \r
+                          STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r
+                          gShellLevel1HiiHandle, \r
+                          ArgSet, \r
+                          CurrentScriptFile!=NULL \r
+                            && CurrentScriptFile->CurrentCommand!=NULL\r
+                            ? CurrentScriptFile->CurrentCommand->Line:0);\r
+                        ShellStatus = SHELL_INVALID_PARAMETER;\r
+                      }\r
                     }\r
                   }\r
+                  \r
                 }\r
-                \r
               }\r
             }\r
           }\r
         }\r
-      }\r
-      if (ShellStatus == SHELL_SUCCESS) {\r
-        if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {\r
-          Info->RemoveSubstAlias  = FALSE;\r
-        } else {\r
-          Info->RemoveSubstAlias  = TRUE;\r
+        if (ShellStatus == SHELL_SUCCESS) {\r
+          if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {\r
+            Info->RemoveSubstAlias  = FALSE;\r
+          } else {\r
+            Info->RemoveSubstAlias  = TRUE;\r
+          }\r
+        }\r
+        if (CurrentScriptFile->CurrentCommand != NULL) {\r
+          CurrentScriptFile->CurrentCommand->Data = Info;\r
         }\r
-      }\r
-      if (CurrentScriptFile->CurrentCommand != NULL) {\r
-        CurrentScriptFile->CurrentCommand->Data = Info;\r
       }\r
     } else {\r
       ShellPrintHiiEx(\r
@@ -665,27 +673,30 @@ ShellCommandRunFor (
         //\r
         ASSERT(TempString == NULL);\r
         TempString = StrnCatGrow(&TempString, NULL, Info->CurrentValue, 0);\r
-        TempSpot   = StrStr(TempString, L"\" \"");\r
-        if (TempSpot != NULL) {\r
-          *TempSpot = CHAR_NULL;\r
-        }\r
-        while (TempString[StrLen(TempString)-1] == L'\"') {\r
-          TempString[StrLen(TempString)-1] = CHAR_NULL;\r
-        }\r
-        InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);\r
-        Info->CurrentValue += StrLen(TempString);\r
+        if (TempString == NULL) {\r
+          ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+        } else {\r
+          TempSpot   = StrStr(TempString, L"\" \"");\r
+          if (TempSpot != NULL) {\r
+            *TempSpot = CHAR_NULL;\r
+          }\r
+          while (TempString[StrLen(TempString)-1] == L'\"') {\r
+            TempString[StrLen(TempString)-1] = CHAR_NULL;\r
+          }\r
+          InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);\r
+          Info->CurrentValue += StrLen(TempString);\r
 \r
-        if (Info->CurrentValue[0] == L'\"') {\r
-          Info->CurrentValue++;\r
-        }\r
-        while (Info->CurrentValue[0] == L' ') {\r
-          Info->CurrentValue++;\r
-        }\r
-        if (Info->CurrentValue[0] == L'\"') {\r
-          Info->CurrentValue++;\r
+          if (Info->CurrentValue[0] == L'\"') {\r
+            Info->CurrentValue++;\r
+          }\r
+          while (Info->CurrentValue[0] == L' ') {\r
+            Info->CurrentValue++;\r
+          }\r
+          if (Info->CurrentValue[0] == L'\"') {\r
+            Info->CurrentValue++;\r
+          }\r
+          FreePool(TempString);\r
         }\r
-        FreePool(TempString);\r
-\r
       } else {\r
         CurrentScriptFile->CurrentCommand->Data = NULL;\r
         //\r
index d305306..0892731 100644 (file)
@@ -739,6 +739,9 @@ MoveToTagSpecial (
     //\r
     CommandName   = NULL;\r
     CommandName   = StrnCatGrow(&CommandName, NULL, CommandNode->Cl, 0);\r
+    if (CommandName == NULL) {\r
+      continue;\r
+    }\r
     CommandWalker = CommandName;\r
     while (CommandWalker[0] == L' ') {\r
       CommandWalker++;\r
index a9dd6cc..6f67f49 100644 (file)
@@ -145,6 +145,10 @@ TestNodeForMove (
   //\r
   CommandName   = NULL;\r
   CommandName   = StrnCatGrow(&CommandName, NULL, CommandNode->Cl, 0);\r
+  if (CommandName == NULL) {\r
+    return (FALSE);\r
+  }\r
+\r
   CommandNameWalker = CommandName;\r
   while(CommandNameWalker[0] == L' ') {\r
     CommandNameWalker++;\r
index 358f63d..a1f9448 100644 (file)
@@ -414,6 +414,9 @@ PerformSingleMappingDisplay(
 \r
   CurrentName = NULL;\r
   CurrentName = StrnCatGrow(&CurrentName, 0, MapList, 0);\r
+  if (CurrentName == NULL) {\r
+    return (EFI_OUT_OF_RESOURCES);\r
+  }\r
   TempSpot = StrStr(CurrentName, L";");\r
   if (TempSpot != NULL) {\r
     *TempSpot = CHAR_NULL;\r
index aa40bbf..f2f2e60 100644 (file)
@@ -642,10 +642,15 @@ CheckAndSetTimeZone (
   }\r
 \r
   Status = gRT->GetTime(&TheTime, NULL);\r
-  ASSERT_EFI_ERROR(Status);\r
+  if (EFI_ERROR(Status)) {\r
+    return (SHELL_DEVICE_ERROR);\r
+  }\r
 \r
   TimeZoneCopy = NULL;\r
   TimeZoneCopy = StrnCatGrow(&TimeZoneCopy, NULL, TimeZoneString, 0);\r
+  if (TimeZoneCopy == NULL) {\r
+    return (SHELL_OUT_OF_RESOURCES);\r
+  }\r
   Walker = TimeZoneCopy;\r
   Walker2 = StrStr(Walker, L":");\r
   if (Walker2 != NULL && *Walker2 == L':') {\r
index 6bdc39f..b153d2f 100644 (file)
@@ -226,6 +226,10 @@ VerifyIntermediateDirectories (
   PathCopy    = StrnCatGrow(&PathCopy, NULL, Path, 0);\r
   FileHandle  = NULL;\r
 \r
+  if (PathCopy == NULL) {\r
+    return (EFI_OUT_OF_RESOURCES);\r
+  }\r
+\r
   for (TempSpot = &PathCopy[StrLen(PathCopy)-1] ; *TempSpot != CHAR_NULL && *TempSpot != L'\\' ; TempSpot = &PathCopy[StrLen(PathCopy)-1]){\r
     *TempSpot = CHAR_NULL;\r
   }\r
index 7eb3c8c..29f6be3 100644 (file)
@@ -79,11 +79,16 @@ DoTouchByHandle (
 \r
   if (FS == NULL) {\r
     FS = StrnCatGrow(&FS, NULL, Name, 0);\r
-    TempSpot = StrStr(FS, L"\\");\r
-    if (TempSpot != NULL) {\r
-      *TempSpot = CHAR_NULL;\r
+    if (FS != NULL) {\r
+      TempSpot = StrStr(FS, L"\\");\r
+      if (TempSpot != NULL) {\r
+        *TempSpot = CHAR_NULL;\r
+      }\r
     }\r
   }\r
+  if (FS == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
 \r
   //\r
   // do it\r