]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ShellParametersProtocol.c
ShellPkg: Add checking for memory allocation and pointer returns from functions.
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellParametersProtocol.c
index 3d138825ff69c4cd73c6743cca64eeecd0e56bfe..55cf3c279eb74401d6d62ed64b3095094f80a42d 100644 (file)
@@ -26,9 +26,9 @@
   Temp Parameter must be large enough to hold the parameter before calling this\r
   function.\r
 \r
-  @param[in,out] Walker        pointer to string of command line.  Adjusted to\r
+  @param[in, out] Walker        pointer to string of command line.  Adjusted to\r
                                 reminaing command line on return\r
-  @param[in,out] TempParameter pointer to string of command line item extracted.\r
+  @param[in, out] TempParameter pointer to string of command line item extracted.\r
 \r
 **/\r
 VOID\r
@@ -69,14 +69,8 @@ GetNextParameter(
   if ((*Walker)[0] == L'\"') {\r
     NextDelim = NULL;\r
     for (TempLoc = *Walker + 1 ; TempLoc != NULL && *TempLoc != CHAR_NULL ; TempLoc++) {\r
-      if (*TempLoc == L'^' && *(TempLoc+1) == L'^') {\r
+      if (*TempLoc == L'^' && *(TempLoc+1) == L'\"') {\r
         TempLoc++;\r
-      } else if (*TempLoc == L'^' && *(TempLoc+1) == L'\"') {\r
-        TempLoc++;\r
-      } else if (*TempLoc == L'^' && *(TempLoc+1) == L'|') {\r
-        TempLoc++;\r
-      } else if (*TempLoc == L'^') {\r
-        *TempLoc = L' ';\r
       } else if (*TempLoc == L'\"') {\r
         NextDelim = TempLoc;\r
         break;\r
@@ -100,10 +94,7 @@ GetNextParameter(
       *Walker = NULL;\r
     }\r
     for (TempLoc = *TempParameter ; TempLoc != NULL && *TempLoc != CHAR_NULL ; TempLoc++) {\r
-      if ((*TempLoc == L'^' && *(TempLoc+1) == L'^')\r
-       || (*TempLoc == L'^' && *(TempLoc+1) == L'|')\r
-       || (*TempLoc == L'^' && *(TempLoc+1) == L'\"')\r
-      ){\r
+      if (*TempLoc == L'^' && *(TempLoc+1) == L'\"') {\r
         CopyMem(TempLoc, TempLoc+1, StrSize(TempLoc) - sizeof(TempLoc[0]));\r
       }\r
     }\r
@@ -127,9 +118,7 @@ GetNextParameter(
     for (NextDelim = *TempParameter ; NextDelim != NULL && *NextDelim != CHAR_NULL ; NextDelim++) {\r
       if (*NextDelim == L'^' && *(NextDelim+1) == L'^') {\r
         CopyMem(NextDelim, NextDelim+1, StrSize(NextDelim) - sizeof(NextDelim[0]));\r
-      }/* else if (*NextDelim == L'^') {\r
-        *NextDelim = L' ';\r
-      }*/\r
+      }\r
     }\r
     while ((*TempParameter)[StrLen(*TempParameter)-1] == L' ') {\r
       (*TempParameter)[StrLen(*TempParameter)-1] = CHAR_NULL;\r
@@ -148,9 +137,9 @@ GetNextParameter(
   parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL.  this supports space\r
   delimited and quote surrounded parameter definition.\r
 \r
-  @param[in] CommandLine        String of command line to parse\r
-  @param[in,out] Argv           pointer to array of strings; one for each parameter\r
-  @param[in,out] Argc           pointer to number of strings in Argv array\r
+  @param[in] CommandLine         String of command line to parse\r
+  @param[in, out] Argv           pointer to array of strings; one for each parameter\r
+  @param[in, out] Argc           pointer to number of strings in Argv array\r
 \r
   @return EFI_SUCCESS           the operation was sucessful\r
   @return EFI_OUT_OF_RESOURCES  a memory allocation failed.\r
@@ -226,9 +215,9 @@ ParseCommandLineToArgs(
   installs it on our handle and if there is an existing version of the protocol\r
   that one is cached for removal later.\r
 \r
-  @param[in,out] NewShellParameters on a successful return, a pointer to pointer\r
+  @param[in, out] NewShellParameters on a successful return, a pointer to pointer\r
                                      to the newly installed interface.\r
-  @param[in,out] RootShellInstance  on a successful return, pointer to boolean.\r
+  @param[in, out] RootShellInstance  on a successful return, pointer to boolean.\r
                                      TRUE if this is the root shell instance.\r
 \r
   @retval EFI_SUCCESS               the operation completed successfully.\r
@@ -419,6 +408,14 @@ CleanUpShellParametersProtocol (
   return (Status);\r
 }\r
 \r
+/**\r
+  Determin if a file name represents a unicode file.\r
+\r
+  @param[in] FileName     Pointer to the filename to open.\r
+\r
+  @retval EFI_SUCCESS     The file is a unicode file.\r
+  @return An error upon failure.\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 IsUnicodeFile(\r
@@ -447,6 +444,57 @@ IsUnicodeFile(
   return (Status);  \r
 }\r
 \r
+/**\r
+  Strips out quotes sections of a string.\r
+\r
+  All of the characters between quotes is replaced with spaces.\r
+\r
+  @param[in, out] TheString  A pointer to the string to update.\r
+**/\r
+VOID\r
+EFIAPI\r
+StripQuotes (\r
+  IN OUT CHAR16 *TheString\r
+  )\r
+{\r
+  BOOLEAN RemoveNow;\r
+\r
+  for (RemoveNow = FALSE ; TheString != NULL && *TheString != CHAR_NULL ; TheString++) {\r
+    if (*TheString == L'^' && *(TheString + 1) == L'\"') {\r
+      TheString++;\r
+    } else if (*TheString == L'\"') {\r
+      RemoveNow = (BOOLEAN)!RemoveNow;\r
+    } else if (RemoveNow) {\r
+      *TheString = L' ';\r
+    }\r
+  }\r
+}\r
+\r
+/**\r
+  Calcualte the 32-bit CRC in a EFI table using the service provided by the\r
+  gRuntime service.\r
+\r
+  @param  Hdr                    Pointer to an EFI standard header\r
+\r
+**/\r
+VOID\r
+CalculateEfiHdrCrc (\r
+  IN  OUT EFI_TABLE_HEADER    *Hdr\r
+  )\r
+{\r
+  UINT32 Crc;\r
+\r
+  Hdr->CRC32 = 0;\r
+\r
+  //\r
+  // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then\r
+  //  Crc will come back as zero if we set it to zero here\r
+  //\r
+  Crc = 0;\r
+  gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);\r
+  Hdr->CRC32 = Crc;\r
+}\r
+\r
 /**\r
   Funcion will replace the current StdIn and StdOut in the ShellParameters protocol\r
   structure by parsing NewCommandLine.  The current values are returned to the\r
@@ -454,12 +502,12 @@ IsUnicodeFile(
 \r
   This will also update the system table.\r
 \r
-  @param[in,out] ShellParameters        Pointer to parameter structure to modify.\r
-  @param[in] NewCommandLine             The new command line to parse and use.\r
-  @param[out] OldStdIn                  Pointer to old StdIn.\r
-  @param[out] OldStdOut                 Pointer to old StdOut.\r
-  @param[out] OldStdErr                 Pointer to old StdErr.\r
-  @param[out] SystemTableInfo           Pointer to old system table information.\r
+  @param[in, out] ShellParameters        Pointer to parameter structure to modify.\r
+  @param[in] NewCommandLine              The new command line to parse and use.\r
+  @param[out] OldStdIn                   Pointer to old StdIn.\r
+  @param[out] OldStdOut                  Pointer to old StdOut.\r
+  @param[out] OldStdErr                  Pointer to old StdErr.\r
+  @param[out] SystemTableInfo            Pointer to old system table information.\r
 \r
   @retval   EFI_SUCCESS                 Operation was sucessful, Argv and Argc are valid.\r
   @retval   EFI_OUT_OF_RESOURCES        A memory allocation failed.\r
@@ -468,7 +516,7 @@ EFI_STATUS
 EFIAPI\r
 UpdateStdInStdOutStdErr(\r
   IN OUT EFI_SHELL_PARAMETERS_PROTOCOL  *ShellParameters,\r
-  IN CONST CHAR16                       *NewCommandLine,\r
+  IN CHAR16                             *NewCommandLine,\r
   OUT SHELL_FILE_HANDLE                 *OldStdIn,\r
   OUT SHELL_FILE_HANDLE                 *OldStdOut,\r
   OUT SHELL_FILE_HANDLE                 *OldStdErr,\r
@@ -494,6 +542,7 @@ UpdateStdInStdOutStdErr(
   UINTN             Size;\r
   CHAR16            TagBuffer[2];\r
   SPLIT_LIST        *Split;\r
+  CHAR16            *FirstLocation;\r
 \r
   OutUnicode      = TRUE;\r
   InUnicode       = TRUE;\r
@@ -507,6 +556,7 @@ UpdateStdInStdOutStdErr(
   ErrAppend       = FALSE;\r
   OutAppend       = FALSE;\r
   CommandLineCopy = NULL;\r
+  FirstLocation   = NULL;\r
 \r
   if (ShellParameters == NULL || SystemTableInfo == NULL || OldStdIn == NULL || OldStdOut == NULL || OldStdErr == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
@@ -527,8 +577,14 @@ 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
+\r
+  StripQuotes(CommandLineCopy);\r
 \r
   if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {\r
     Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);\r
@@ -541,6 +597,7 @@ UpdateStdInStdOutStdErr(
   }\r
 \r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>>v ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 12, L' ');\r
     StdErrVarName   = CommandLineWalker += 6;\r
     ErrAppend       = TRUE;\r
@@ -549,6 +606,7 @@ UpdateStdInStdOutStdErr(
     }\r
   }\r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>v ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 12, L' ');\r
     StdOutVarName   = CommandLineWalker += 6;\r
     OutAppend       = TRUE;\r
@@ -556,6 +614,7 @@ UpdateStdInStdOutStdErr(
       Status = EFI_NOT_FOUND;\r
     }\r
   } else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>v ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 10, L' ');\r
     StdOutVarName   = CommandLineWalker += 5;\r
     OutAppend       = TRUE;\r
@@ -563,6 +622,7 @@ UpdateStdInStdOutStdErr(
       Status = EFI_NOT_FOUND;\r
     }\r
   } else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >v ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 8, L' ');\r
     StdOutVarName   = CommandLineWalker += 4;\r
     OutAppend       = FALSE;\r
@@ -571,6 +631,7 @@ UpdateStdInStdOutStdErr(
     }\r
   }\r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>a ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 12, L' ');\r
     StdOutFileName  = CommandLineWalker += 6;\r
     OutAppend       = TRUE;\r
@@ -580,6 +641,7 @@ UpdateStdInStdOutStdErr(
     }\r
   }\r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>> ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 10, L' ');\r
     if (StdOutFileName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -592,6 +654,7 @@ UpdateStdInStdOutStdErr(
     }\r
   } \r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >> ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 8, L' ');\r
     if (StdOutFileName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -604,6 +667,7 @@ UpdateStdInStdOutStdErr(
     }\r
   }\r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>a ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 10, L' ');\r
     if (StdOutFileName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -617,6 +681,7 @@ UpdateStdInStdOutStdErr(
     }\r
   } \r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>a ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 10, L' ');\r
     if (StdOutFileName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -630,6 +695,7 @@ UpdateStdInStdOutStdErr(
     }\r
   } \r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >a ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 8, L' ');\r
     if (StdOutFileName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -643,6 +709,7 @@ UpdateStdInStdOutStdErr(
     }\r
   }\r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>> ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 10, L' ');\r
     if (StdErrFileName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -656,6 +723,7 @@ UpdateStdInStdOutStdErr(
   }\r
 \r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>v ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 10, L' ');\r
     if (StdErrVarName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -668,6 +736,7 @@ UpdateStdInStdOutStdErr(
     }\r
   }\r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>v ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 10, L' ');\r
     if (StdOutVarName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -680,6 +749,7 @@ UpdateStdInStdOutStdErr(
     }\r
   }\r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>a ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 10, L' ');\r
     if (StdErrFileName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -693,6 +763,7 @@ UpdateStdInStdOutStdErr(
     }\r
   }\r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2> ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 8, L' ');\r
     if (StdErrFileName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -706,6 +777,7 @@ UpdateStdInStdOutStdErr(
   }\r
 \r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1> ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 8, L' ');\r
     if (StdOutFileName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -719,6 +791,7 @@ UpdateStdInStdOutStdErr(
   }\r
 \r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" > ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 6, L' ');\r
     if (StdOutFileName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -732,6 +805,7 @@ UpdateStdInStdOutStdErr(
   }\r
 \r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" < ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 6, L' ');\r
     if (StdInFileName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -743,6 +817,7 @@ UpdateStdInStdOutStdErr(
     }\r
   }\r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" <a ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 8, L' ');\r
     if (StdInFileName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -755,6 +830,7 @@ UpdateStdInStdOutStdErr(
     }\r
   }\r
   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" <v ")) != NULL) {\r
+    FirstLocation = MIN(CommandLineWalker, FirstLocation);\r
     SetMem16(CommandLineWalker, 8, L' ');\r
     if (StdInVarName != NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -766,6 +842,12 @@ UpdateStdInStdOutStdErr(
     }\r
   }\r
 \r
+  if (FirstLocation != CommandLineCopy + StrLen(CommandLineCopy)\r
+    && ((UINTN)(FirstLocation - CommandLineCopy) < StrLen(NewCommandLine))\r
+    ){\r
+    *(NewCommandLine + (UINTN)(FirstLocation - CommandLineCopy)) = CHAR_NULL;\r
+  }\r
+\r
   if (!EFI_ERROR(Status)) {\r
     if (StdErrFileName != NULL && (CommandLineWalker = StrStr(StdErrFileName, L" ")) != NULL) {\r
       CommandLineWalker[0] = CHAR_NULL;\r
@@ -793,7 +875,7 @@ UpdateStdInStdOutStdErr(
       //\r
       // Check that no 2 filenames are the same\r
       //\r
-        (StdErrFileName != NULL && StdOutFileName!= NULL && StringNoCaseCompare(&StdErrFileName, &StdOutFileName) == 0)\r
+      (StdErrFileName != NULL && StdOutFileName!= NULL && StringNoCaseCompare(&StdErrFileName, &StdOutFileName) == 0)\r
       ||(StdErrFileName != NULL && StdInFileName != NULL && StringNoCaseCompare(&StdErrFileName, &StdInFileName ) == 0)\r
       ||(StdOutFileName != NULL && StdInFileName != NULL && StringNoCaseCompare(&StdOutFileName, &StdInFileName ) == 0)\r
       //\r
@@ -814,11 +896,6 @@ UpdateStdInStdOutStdErr(
       ||(StdOutFileName != NULL && StdOutVarName != NULL)\r
       ||(StdInFileName  != NULL && StdInVarName  != NULL)\r
       //\r
-      // There should not be extra > or <\r
-      //\r
-      ||(StrStr(CommandLineCopy, L"<") != NULL)\r
-      ||(StrStr(CommandLineCopy, L">") != NULL)\r
-      //\r
       // Check for no volatile environment variables\r
       //\r
       ||(StdErrVarName  != NULL && !IsVolatileEnv(StdErrVarName))\r
@@ -837,7 +914,10 @@ UpdateStdInStdOutStdErr(
       ||(StdErrFileName != NULL && !ErrUnicode && ErrAppend && (!EFI_ERROR(ShellFileExists(StdErrFileName)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName))))\r
       ){\r
       Status = EFI_INVALID_PARAMETER;\r
-    } else {\r
+      ShellParameters->StdIn  = *OldStdIn;\r
+      ShellParameters->StdOut = *OldStdOut;\r
+      ShellParameters->StdErr = *OldStdErr;\r
+    } else if (!EFI_ERROR(Status)){\r
       //\r
       // Open the Std<Whatever> and we should not have conflicts here...\r
       //\r
@@ -953,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
@@ -987,6 +1070,8 @@ UpdateStdInStdOutStdErr(
   }\r
   FreePool(CommandLineCopy);\r
 \r
+  CalculateEfiHdrCrc(&gST->Hdr);\r
+\r
   if (gST->ConIn == NULL ||gST->ConOut == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
@@ -997,11 +1082,11 @@ UpdateStdInStdOutStdErr(
   Funcion will replace the current StdIn and StdOut in the ShellParameters protocol\r
   structure with StdIn and StdOut.  The current values are de-allocated.\r
 \r
-  @param[in,out] ShellParameters      Pointer to parameter structure to modify.\r
-  @param[in] OldStdIn                 Pointer to old StdIn.\r
-  @param[in] OldStdOut                Pointer to old StdOut.\r
-  @param[in] OldStdErr                Pointer to old StdErr.\r
-  @param[in] SystemTableInfo          Pointer to old system table information.\r
+  @param[in, out] ShellParameters      Pointer to parameter structure to modify.\r
+  @param[in] OldStdIn                  Pointer to old StdIn.\r
+  @param[in] OldStdOut                 Pointer to old StdOut.\r
+  @param[in] OldStdErr                 Pointer to old StdErr.\r
+  @param[in] SystemTableInfo           Pointer to old system table information.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -1060,6 +1145,8 @@ RestoreStdInStdOutStdErr (
     gST->StandardErrorHandle  = SystemTableInfo->ConErrHandle;\r
   }\r
 \r
+  CalculateEfiHdrCrc(&gST->Hdr);\r
+\r
   return (EFI_SUCCESS);\r
 }\r
 /**\r
@@ -1069,10 +1156,10 @@ RestoreStdInStdOutStdErr (
 \r
   If OldArgv or OldArgc is NULL then that value is not returned.\r
 \r
-  @param[in,out] ShellParameters        Pointer to parameter structure to modify.\r
-  @param[in] NewCommandLine             The new command line to parse and use.\r
-  @param[out] OldArgv                   Pointer to old list of parameters.\r
-  @param[out] OldArgc                   Pointer to old number of items in Argv list.\r
+  @param[in, out] ShellParameters        Pointer to parameter structure to modify.\r
+  @param[in] NewCommandLine              The new command line to parse and use.\r
+  @param[out] OldArgv                    Pointer to old list of parameters.\r
+  @param[out] OldArgc                    Pointer to old number of items in Argv list.\r
 \r
   @retval   EFI_SUCCESS                 Operation was sucessful, Argv and Argc are valid.\r
   @retval   EFI_OUT_OF_RESOURCES        A memory allocation failed.\r
@@ -1103,9 +1190,9 @@ UpdateArgcArgv(
   structure with Argv and Argc.  The current values are de-allocated and the\r
   OldArgv must not be deallocated by the caller.\r
 \r
-  @param[in,out] ShellParameters       pointer to parameter structure to modify\r
-  @param[in] OldArgv                   pointer to old list of parameters\r
-  @param[in] OldArgc                   pointer to old number of items in Argv list\r
+  @param[in, out] ShellParameters       pointer to parameter structure to modify\r
+  @param[in] OldArgv                    pointer to old list of parameters\r
+  @param[in] OldArgc                    pointer to old number of items in Argv list\r
 **/\r
 VOID\r
 EFIAPI\r