/** @file\r
This is THE shell (application)\r
\r
- Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
(C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
return (Temp);\r
}\r
\r
+/**\r
+ Check whether the string between a pair of % is a valid envifronment variable name.\r
+\r
+ @param[in] BeginPercent pointer to the first percent.\r
+ @param[in] EndPercent pointer to the last percent.\r
+\r
+ @retval TRUE is a valid environment variable name.\r
+ @retval FALSE is NOT a valid environment variable name.\r
+**/\r
+BOOLEAN\r
+IsValidEnvironmentVariableName(\r
+ IN CONST CHAR16 *BeginPercent,\r
+ IN CONST CHAR16 *EndPercent\r
+ )\r
+{\r
+ CONST CHAR16 *Walker;\r
+ \r
+ Walker = NULL;\r
+\r
+ ASSERT (BeginPercent != NULL);\r
+ ASSERT (EndPercent != NULL);\r
+ ASSERT (BeginPercent < EndPercent);\r
+ \r
+ if ((BeginPercent + 1) == EndPercent) {\r
+ return FALSE;\r
+ }\r
+\r
+ for (Walker = BeginPercent + 1; Walker < EndPercent; Walker++) {\r
+ if (\r
+ (*Walker >= L'0' && *Walker <= L'9') ||\r
+ (*Walker >= L'A' && *Walker <= L'Z') ||\r
+ (*Walker >= L'a' && *Walker <= L'z') ||\r
+ (*Walker == L'_')\r
+ ) {\r
+ if (Walker == BeginPercent + 1 && (*Walker >= L'0' && *Walker <= L'9')) {\r
+ return FALSE;\r
+ } else {\r
+ continue;\r
+ }\r
+ } else {\r
+ return FALSE;\r
+ }\r
+ }\r
+\r
+ return TRUE;\r
+}\r
+\r
/**\r
Find a command line contains a split operation\r
\r
break;\r
}\r
\r
- if (FirstQuote < FirstPercent) {\r
- SecondQuote = FirstQuote!= NULL?FindNextInstance(FirstQuote+1, L"\"", TRUE):NULL;\r
+ if (FirstQuote!= NULL && FirstQuote < FirstPercent) {\r
+ SecondQuote = FindNextInstance(FirstQuote+1, L"\"", TRUE);\r
//\r
// Quote is first found\r
//\r
}\r
continue;\r
}\r
- ASSERT(FirstPercent < FirstQuote);\r
- if (SecondPercent < FirstQuote) {\r
- FirstPercent[0] = L'\"';\r
- SecondPercent[0] = L'\"';\r
-\r
- //\r
- // We need to remove from FirstPercent to SecondPercent\r
- //\r
- CopyMem(FirstPercent + 1, SecondPercent, StrSize(SecondPercent));\r
- CurrentLocator = FirstPercent + 2;\r
+ \r
+ if (FirstQuote == NULL || SecondPercent < FirstQuote) {\r
+ if (IsValidEnvironmentVariableName(FirstPercent, SecondPercent)) {\r
+ //\r
+ // We need to remove from FirstPercent to SecondPercent\r
+ //\r
+ CopyMem(FirstPercent, SecondPercent + 1, StrSize(SecondPercent + 1));\r
+ //\r
+ // dont need to update the locator. both % characters are gone.\r
+ //\r
+ } else {\r
+ CurrentLocator = SecondPercent + 1;\r
+ }\r
continue;\r
}\r
- ASSERT(FirstQuote < SecondPercent);\r
CurrentLocator = FirstQuote;\r
}\r
return (EFI_SUCCESS);\r
ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);\r
StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);\r
}\r
-\r
- //\r
- // Remove non-existant environment variables in scripts only\r
- //\r
- StripUnreplacedEnvironmentVariables(NewCommandLine1);\r
}\r
\r
+ //\r
+ // Remove non-existant environment variables\r
+ //\r
+ StripUnreplacedEnvironmentVariables(NewCommandLine1);\r
+\r
//\r
// Now cleanup any straggler intentionally ignored "%" characters\r
//\r
return (EFI_OUT_OF_RESOURCES);\r
}\r
TempWalker = (CHAR16*)Temp;\r
- GetNextParameter(&TempWalker, &FirstParameter, StrSize(CmdLine));\r
-\r
- if (GetOperationType(FirstParameter) == Unknown_Invalid) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
- SetLastError(SHELL_NOT_FOUND);\r
- Status = EFI_NOT_FOUND;\r
+ if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CmdLine)))) {\r
+ if (GetOperationType(FirstParameter) == Unknown_Invalid) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
+ SetLastError(SHELL_NOT_FOUND);\r
+ Status = EFI_NOT_FOUND;\r
+ }\r
}\r
}\r
\r
Walker = *CmdLine;\r
while(Walker != NULL && *Walker != CHAR_NULL) {\r
LastWalker = Walker;\r
- GetNextParameter(&Walker, &CurrentParameter, StrSize(*CmdLine));\r
- if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {\r
- LastWalker[0] = L' ';\r
- LastWalker[1] = L' ';\r
- NewCommandLine = AllocateZeroPool(StrSize(L"help ") + StrSize(*CmdLine));\r
- if (NewCommandLine == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
+ if (!EFI_ERROR(GetNextParameter(&Walker, &CurrentParameter, StrSize(*CmdLine)))) {\r
+ if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {\r
+ LastWalker[0] = L' ';\r
+ LastWalker[1] = L' ';\r
+ NewCommandLine = AllocateZeroPool(StrSize(L"help ") + StrSize(*CmdLine));\r
+ if (NewCommandLine == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ break;\r
+ }\r
+\r
+ //\r
+ // We know the space is sufficient since we just calculated it.\r
+ //\r
+ StrnCpy(NewCommandLine, L"help ", 5);\r
+ StrnCat(NewCommandLine, *CmdLine, StrLen(*CmdLine));\r
+ SHELL_FREE_NON_NULL(*CmdLine);\r
+ *CmdLine = NewCommandLine;\r
break;\r
}\r
-\r
- //\r
- // We know the space is sufficient since we just calculated it.\r
- //\r
- StrnCpy(NewCommandLine, L"help ", 5);\r
- StrnCat(NewCommandLine, *CmdLine, StrLen(*CmdLine));\r
- SHELL_FREE_NON_NULL(*CmdLine);\r
- *CmdLine = NewCommandLine;\r
- break;\r
}\r
}\r
\r
return (EFI_OUT_OF_RESOURCES);\r
}\r
TempWalker = CleanOriginal;\r
- GetNextParameter(&TempWalker, &FirstParameter, StrSize(CleanOriginal));\r
-\r
- //\r
- // Depending on the first parameter we change the behavior\r
- //\r
- switch (Type = GetOperationType(FirstParameter)) {\r
- case File_Sys_Change:\r
- Status = ChangeMappedDrive (FirstParameter);\r
- break;\r
- case Internal_Command:\r
- case Script_File_Name:\r
- case Efi_Application:\r
- Status = SetupAndRunCommandOrFile(Type, CleanOriginal, FirstParameter, ShellInfoObject.NewShellParametersProtocol);\r
- break;\r
- default:\r
- //\r
- // Whatever was typed, it was invalid.\r
- //\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
- SetLastError(SHELL_NOT_FOUND);\r
- break;\r
+ if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CleanOriginal)))) {\r
+ //\r
+ // Depending on the first parameter we change the behavior\r
+ //\r
+ switch (Type = GetOperationType(FirstParameter)) {\r
+ case File_Sys_Change:\r
+ Status = ChangeMappedDrive (FirstParameter);\r
+ break;\r
+ case Internal_Command:\r
+ case Script_File_Name:\r
+ case Efi_Application:\r
+ Status = SetupAndRunCommandOrFile(Type, CleanOriginal, FirstParameter, ShellInfoObject.NewShellParametersProtocol);\r
+ break;\r
+ default:\r
+ //\r
+ // Whatever was typed, it was invalid.\r
+ //\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
+ SetLastError(SHELL_NOT_FOUND);\r
+ break;\r
+ }\r
+ } else {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
+ SetLastError(SHELL_NOT_FOUND);\r
}\r
\r
SHELL_FREE_NON_NULL(CleanOriginal);\r