]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Revert 16720 and 16734.
authorJaben Carsey <Jaben.carsey@intel.com>
Wed, 4 Feb 2015 16:39:04 +0000 (16:39 +0000)
committerjcarsey <jcarsey@Edk2>
Wed, 4 Feb 2015 16:39:04 +0000 (16:39 +0000)
I will submit a new patch.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <Jaben.carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16757 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Application/Shell/Shell.c

index dbf4d61aa9315bc1469463cd19c489fe1c02e170..52b6834ab99ac176829afa8fc0021122aff1c22d 100644 (file)
@@ -100,6 +100,48 @@ TrimSpaces(
   return (EFI_SUCCESS);\r
 }\r
 \r
+/**\r
+  Parse for the next instance of one string within another string. Can optionally make sure that \r
+  the string was not escaped (^ character) per the shell specification.\r
+\r
+  @param[in] SourceString             The string to search within\r
+  @param[in] FindString               The string to look for\r
+  @param[in] CheckForEscapeCharacter  TRUE to skip escaped instances of FinfString, otherwise will return even escaped instances\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+FindNextInstance(\r
+  IN CONST CHAR16   *SourceString,\r
+  IN CONST CHAR16   *FindString,\r
+  IN CONST BOOLEAN  CheckForEscapeCharacter\r
+  )\r
+{\r
+  CHAR16 *Temp;\r
+  if (SourceString == NULL) {\r
+    return (NULL);\r
+  }\r
+  Temp = StrStr(SourceString, FindString);\r
+\r
+  //\r
+  // If nothing found, or we dont care about escape characters\r
+  //\r
+  if (Temp == NULL || !CheckForEscapeCharacter) {\r
+    return (Temp);\r
+  }\r
+\r
+  //\r
+  // If we found an escaped character, try again on the remainder of the string\r
+  //\r
+  if ((Temp > (SourceString)) && *(Temp-1) == L'^') {\r
+    return FindNextInstance(Temp+1, FindString, CheckForEscapeCharacter);\r
+  }\r
+\r
+  //\r
+  // we found the right character\r
+  //\r
+  return (Temp);\r
+}\r
+\r
 /**\r
   Check whether the string between a pair of % is a valid envifronment variable name.\r
 \r
@@ -165,31 +207,32 @@ ContainsSplit(
   CONST CHAR16 *FirstQuote;\r
   CONST CHAR16 *SecondQuote;\r
 \r
-  FirstQuote    = FindFirstCharacter (CmdLine, L"\"", L'^');\r
+  FirstQuote    = FindNextInstance (CmdLine, L"\"", TRUE);\r
   SecondQuote   = NULL;\r
   TempSpot      = FindFirstCharacter(CmdLine, L"|", L'^');\r
 \r
-  if (FirstQuote == NULL    || \r
-      TempSpot == NULL      || \r
-      TempSpot == CHAR_NULL || \r
+  if (FirstQuote == NULL        || \r
+      *FirstQuote == CHAR_NULL  ||\r
+      TempSpot == NULL          || \r
+      *TempSpot == CHAR_NULL    || \r
       FirstQuote > TempSpot\r
       ) {\r
     return (BOOLEAN) ((TempSpot != NULL) && (*TempSpot != CHAR_NULL));\r
   }\r
 \r
   while ((TempSpot != NULL) && (*TempSpot != CHAR_NULL)) {\r
-    if (FirstQuote == NULL || FirstQuote > TempSpot) {\r
+    if (FirstQuote == NULL || *FirstQuote == CHAR_NULL || FirstQuote > TempSpot) {\r
       break;\r
     }    \r
-    SecondQuote = FindFirstCharacter (FirstQuote + 1, L"\"", L'^');\r
-    if (SecondQuote == NULL) {\r
+    SecondQuote = FindNextInstance (FirstQuote + 1, L"\"", TRUE);\r
+    if (SecondQuote == NULL || *SecondQuote == CHAR_NULL) {\r
       break;\r
     }\r
     if (SecondQuote < TempSpot) {\r
-      FirstQuote = FindFirstCharacter (SecondQuote + 1, L"\"", L'^');\r
+      FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);\r
       continue;\r
     } else {\r
-      FirstQuote = FindFirstCharacter (SecondQuote + 1, L"\"", L'^');\r
+      FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);\r
       TempSpot = FindFirstCharacter(TempSpot + 1, L"|", L'^');\r
       continue;\r
     } \r
@@ -1302,9 +1345,9 @@ StripUnreplacedEnvironmentVariables(
   CHAR16 *CurrentLocator;\r
 \r
   for (CurrentLocator = CmdLine ; CurrentLocator != NULL ; ) {\r
-    FirstQuote = (CHAR16*)FindFirstCharacter(CurrentLocator, L"\"", L'^');\r
-    FirstPercent = (CHAR16*)FindFirstCharacter(CurrentLocator, L"%", L'^');\r
-    SecondPercent = FirstPercent!=NULL?(CHAR16*)FindFirstCharacter(FirstPercent+1, L"%", L'^'):NULL;\r
+    FirstQuote = FindNextInstance(CurrentLocator, L"\"", TRUE);\r
+    FirstPercent = FindNextInstance(CurrentLocator, L"%", TRUE);\r
+    SecondPercent = FirstPercent!=NULL?FindNextInstance(FirstPercent+1, L"%", TRUE):NULL;\r
     if (FirstPercent == NULL || SecondPercent == NULL) {\r
       //\r
       // If we ever dont have 2 % we are done.\r
@@ -1313,10 +1356,11 @@ StripUnreplacedEnvironmentVariables(
     }\r
 \r
     if (FirstQuote!= NULL && FirstQuote < FirstPercent) {\r
-      SecondQuote = (CHAR16*)FindFirstCharacter(FirstQuote+1, L"\"", L'^');\r
+      SecondQuote = FindNextInstance(FirstQuote+1, L"\"", TRUE);\r
       //\r
       // Quote is first found\r
       //\r
+\r
       if (SecondQuote < FirstPercent) {\r
         //\r
         // restart after the pair of "\r
@@ -1331,7 +1375,7 @@ StripUnreplacedEnvironmentVariables(
       continue;\r
     }\r
     \r
-    if (FirstQuote == NULL || SecondPercent < FirstQuote) {\r
+    if (FirstQuote == NULL || *FirstQuote == CHAR_NULL || SecondPercent < FirstQuote) {\r
       if (IsValidEnvironmentVariableName(FirstPercent, SecondPercent)) {\r
         //\r
         // We need to remove from FirstPercent to SecondPercent\r