]> git.proxmox.com Git - mirror_edk2.git/commitdiff
remove redirection command line updating from the shell core code.
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 30 Mar 2011 21:04:57 +0000 (21:04 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 30 Mar 2011 21:04:57 +0000 (21:04 +0000)
add redirection command line updating to the redirection support function (UpdateStdInStdOutStdErr).
add more user input verification to redirection.

reduce user input verification from inside quoted parameters.

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

ShellPkg/Application/Shell/Shell.c
ShellPkg/Application/Shell/ShellParametersProtocol.c
ShellPkg/Application/Shell/ShellParametersProtocol.h

index ecd48cdd78719149670ff1f464e955e9d1963b52..a56967189bba7ca7e4b7c09e55ac983a18c0a26f 100644 (file)
@@ -1427,21 +1427,6 @@ RunCommand(
         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle);\r
       }\r
     } else {\r
-      //\r
-      // remove the < and/or > from the command line now\r
-      //\r
-      for (TempLocation3 = PostVariableCmdLine ; TempLocation3 != NULL && *TempLocation3 != CHAR_NULL ; TempLocation3++) {\r
-        if (*TempLocation3 == L'^') {\r
-          if (*(TempLocation3+1) == L'<' || *(TempLocation3+1) == L'>') {\r
-            CopyMem(TempLocation3, TempLocation3+1, StrSize(TempLocation3) - sizeof(TempLocation3[0]));\r
-          }\r
-        } else if (*TempLocation3 == L'>') {\r
-          *TempLocation3 = CHAR_NULL;\r
-        } else if ((*TempLocation3 == L'1' || *TempLocation3 == L'2')&&(*(TempLocation3+1) == L'>')) {\r
-          *TempLocation3 = CHAR_NULL;\r
-        }\r
-      }\r
-\r
       while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') {\r
         PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL;\r
       }\r
index 3d138825ff69c4cd73c6743cca64eeecd0e56bfe..de2d4d1220daf47d9404e11ac36a30a5df07bf6f 100644 (file)
@@ -73,10 +73,6 @@ GetNextParameter(
         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
@@ -447,6 +443,30 @@ 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
+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
   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
@@ -468,7 +488,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 +514,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 +528,7 @@ UpdateStdInStdOutStdErr(
   ErrAppend       = FALSE;\r
   OutAppend       = FALSE;\r
   CommandLineCopy = NULL;\r
+  FirstLocation   = (CHAR16*)(-1);\r
 \r
   if (ShellParameters == NULL || SystemTableInfo == NULL || OldStdIn == NULL || OldStdOut == NULL || OldStdErr == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
@@ -530,6 +552,8 @@ UpdateStdInStdOutStdErr(
   Status          = EFI_SUCCESS;\r
   Split           = NULL;\r
 \r
+  StripQuotes(CommandLineCopy);\r
+\r
   if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {\r
     Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);\r
     if (Split != NULL && Split->SplitStdIn != NULL) {\r
@@ -541,6 +565,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 +574,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 +582,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 +590,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 +599,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 +609,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 +622,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 +635,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 +649,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 +663,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 +677,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 +691,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 +704,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 +717,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 +731,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 +745,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 +759,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 +773,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 +785,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 +798,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 +810,12 @@ UpdateStdInStdOutStdErr(
     }\r
   }\r
 \r
+  if (FirstLocation != (CHAR16*)(-1) \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
@@ -786,14 +836,11 @@ UpdateStdInStdOutStdErr(
       CommandLineWalker[0] = CHAR_NULL;\r
     }\r
 \r
-    //\r
-    // Verify not the same and not duplicating something from a split\r
-    //\r
     if (\r
       //\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 +861,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 +879,7 @@ UpdateStdInStdOutStdErr(
       ||(StdErrFileName != NULL && !ErrUnicode && ErrAppend && (!EFI_ERROR(ShellFileExists(StdErrFileName)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName))))\r
       ){\r
       Status = EFI_INVALID_PARAMETER;\r
-    } else {\r
+    } else if (!EFI_ERROR(Status)){\r
       //\r
       // Open the Std<Whatever> and we should not have conflicts here...\r
       //\r
index 2d19587610ea3454d74aa66cc5012517b0e22b24..df3bfa7cbcc2bd8982d35e55eda532ea88c6f927 100644 (file)
@@ -132,7 +132,7 @@ typedef struct {
   structure by parsing NewCommandLine.  The current values are returned to the\r
   user.\r
 \r
-  If OldStdIn or OldStdOut is NULL then that value is not returned.\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
@@ -148,7 +148,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