X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellLevel1CommandsLib%2FFor.c;h=9824977149193ebab07c8c1420e80a991340c67b;hp=4fdbdd051d4c48b439b1b74c4c8b8fe37c79d1cb;hb=7162fdb037fb9385f6bd7d0dc55d54029b810de2;hpb=81cd2f536ef0097392b51f96405321ce7b01350c
diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
index 4fdbdd051d..9824977149 100644
--- a/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
+++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
@@ -1,7 +1,8 @@
/** @file
Main file for endfor and for shell level 1 functions.
- Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+ (C) Copyright 2015 Hewlett-Packard Development Company, L.P.
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -24,7 +25,6 @@
@retval FALSE The number is not valid.
**/
BOOLEAN
-EFIAPI
ShellIsValidForNumber (
IN CONST CHAR16 *Number
)
@@ -75,12 +75,12 @@ ShellCommandRunEndFor (
ASSERT_EFI_ERROR(Status);
if (!gEfiShellProtocol->BatchIsActive()) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"EndFor");
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"endfor");
return (SHELL_UNSUPPORTED);
}
if (gEfiShellParametersProtocol->Argc > 1) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle, L"endfor");
return (SHELL_INVALID_PARAMETER);
}
@@ -128,7 +128,6 @@ typedef struct {
@retval EFI_OUT_OF_RESOURCES There was not enough free memory.
**/
EFI_STATUS
-EFIAPI
InternalUpdateAliasOnList(
IN CONST CHAR16 *Alias,
IN CONST CHAR16 *CommandString,
@@ -184,7 +183,6 @@ InternalUpdateAliasOnList(
@retval FALSE The alias is not on the list.
**/
BOOLEAN
-EFIAPI
InternalIsAliasOnList(
IN CONST CHAR16 *Alias,
IN CONST LIST_ENTRY *List
@@ -220,7 +218,6 @@ InternalIsAliasOnList(
@param[in, out] List The list to search.
**/
BOOLEAN
-EFIAPI
InternalRemoveAliasFromList(
IN CONST CHAR16 *Alias,
IN OUT LIST_ENTRY *List
@@ -263,7 +260,6 @@ InternalRemoveAliasFromList(
@retval (UINTN)(-1) An error ocurred.
**/
UINTN
-EFIAPI
ReturnUintn(
IN CONST CHAR16 *String
)
@@ -294,6 +290,7 @@ ShellCommandRunFor (
SCRIPT_FILE *CurrentScriptFile;
CHAR16 *ArgSet;
CHAR16 *ArgSetWalker;
+ CHAR16 *Parameter;
UINTN ArgSize;
UINTN LoopVar;
SHELL_FOR_INFO *Info;
@@ -309,6 +306,7 @@ ShellCommandRunFor (
ShellStatus = SHELL_SUCCESS;
ArgSetWalker = NULL;
TempString = NULL;
+ Parameter = NULL;
FirstPass = FALSE;
//
@@ -321,12 +319,12 @@ ShellCommandRunFor (
ASSERT_EFI_ERROR(Status);
if (!gEfiShellProtocol->BatchIsActive()) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"For");
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"for");
return (SHELL_UNSUPPORTED);
}
if (gEfiShellParametersProtocol->Argc < 4) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle, L"for");
return (SHELL_INVALID_PARAMETER);
}
@@ -391,9 +389,15 @@ ShellCommandRunFor (
ShellCloseFileMetaArg(&FileList);
}
} else {
- ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
- ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
- ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
+ Parameter = gEfiShellParametersProtocol->Argv[LoopVar];
+ if (Parameter[0] == L'\"' && Parameter[StrLen(Parameter)-1] == L'\"') {
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Parameter, 0);
+ } else {
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Parameter, 0);
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
+ }
}
}
if (ArgSet == NULL) {
@@ -405,7 +409,10 @@ ShellCommandRunFor (
NewSize = StrSize(ArgSet);
NewSize += sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]);
Info = AllocateZeroPool(NewSize);
- ASSERT(Info != NULL);
+ if (Info == NULL) {
+ FreePool (ArgSet);
+ return SHELL_OUT_OF_RESOURCES;
+ }
Info->Signature = SHELL_FOR_INFO_SIGNATURE;
CopyMem(Info->Set, ArgSet, StrSize(ArgSet));
NewSize = StrSize(gEfiShellParametersProtocol->Argv[1]);
@@ -429,6 +436,11 @@ ShellCommandRunFor (
gEfiShellParametersProtocol->Argv[2]) == 0) {
for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));
+ if (StrStr (gEfiShellParametersProtocol->Argv[LoopVar], L")") != NULL &&
+ (LoopVar + 1) < gEfiShellParametersProtocol->Argc
+ ) {
+ return (SHELL_INVALID_PARAMETER);
+ }
if (ArgSet == NULL) {
// ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
} else {
@@ -444,7 +456,10 @@ ShellCommandRunFor (
// set up for a 'run' for loop
//
Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]));
- ASSERT(Info != NULL);
+ if (Info == NULL) {
+ FreePool (ArgSet);
+ return SHELL_OUT_OF_RESOURCES;
+ }
Info->Signature = SHELL_FOR_INFO_SIGNATURE;
CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1]));
Info->ReplacementName = Info->Set;
@@ -609,7 +624,9 @@ ShellCommandRunFor (
if (CurrentScriptFile != NULL && CurrentScriptFile->CurrentCommand != NULL) {
Info = (SHELL_FOR_INFO*)CurrentScriptFile->CurrentCommand->Data;
if (CurrentScriptFile->CurrentCommand->Reset) {
- Info->CurrentValue = (CHAR16*)Info->Set;
+ if (Info != NULL) {
+ Info->CurrentValue = (CHAR16*)Info->Set;
+ }
FirstPass = TRUE;
CurrentScriptFile->CurrentCommand->Reset = FALSE;
}
@@ -692,12 +709,6 @@ ShellCommandRunFor (
InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);
Info->CurrentValue += StrLen(TempString);
- if (Info->CurrentValue[0] == L'\"') {
- Info->CurrentValue++;
- }
- while (Info->CurrentValue[0] == L' ') {
- Info->CurrentValue++;
- }
if (Info->CurrentValue[0] == L'\"') {
Info->CurrentValue++;
}