ShellPkg: update behavior with undefined environment variables
Undefined environment variables are now removed during script execution. Excepted environment variables are now correctly un-excepted right before processing continues Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jaben Carsey <Jaben.carsey@intel.com> reviewed-by: Matthews, Robert <Robert.Matthews@hp.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14585 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@ -1085,6 +1085,7 @@ ShellConvertVariables (
|
|||||||
CHAR16 *NewCommandLine1;
|
CHAR16 *NewCommandLine1;
|
||||||
CHAR16 *NewCommandLine2;
|
CHAR16 *NewCommandLine2;
|
||||||
CHAR16 *Temp;
|
CHAR16 *Temp;
|
||||||
|
CHAR16 *Temp2;
|
||||||
UINTN ItemSize;
|
UINTN ItemSize;
|
||||||
CHAR16 *ItemTemp;
|
CHAR16 *ItemTemp;
|
||||||
SCRIPT_FILE *CurrentScriptFile;
|
SCRIPT_FILE *CurrentScriptFile;
|
||||||
@ -1142,15 +1143,6 @@ ShellConvertVariables (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Quick out if none were found...
|
|
||||||
//
|
|
||||||
if (NewSize == StrSize(OriginalCommandLine)) {
|
|
||||||
ASSERT(Temp == NULL);
|
|
||||||
Temp = StrnCatGrow(&Temp, NULL, OriginalCommandLine, 0);
|
|
||||||
return (Temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// now do the replacements...
|
// now do the replacements...
|
||||||
//
|
//
|
||||||
@ -1182,7 +1174,50 @@ ShellConvertVariables (
|
|||||||
ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);
|
ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);
|
||||||
StrCpy(NewCommandLine1, NewCommandLine2);
|
StrCpy(NewCommandLine1, NewCommandLine2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Remove non-existant environment variables in scripts only
|
||||||
|
//
|
||||||
|
for (Temp = NewCommandLine1 ; Temp != NULL ; ) {
|
||||||
|
Temp = StrStr(Temp, L"%");
|
||||||
|
if (Temp == NULL) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
while (*(Temp - 1) == L'^') {
|
||||||
|
Temp = StrStr(Temp + 1, L"%");
|
||||||
|
if (Temp == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Temp == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Temp2 = StrStr(Temp + 1, L"%");
|
||||||
|
if (Temp2 == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while (*(Temp2 - 1) == L'^') {
|
||||||
|
Temp2 = StrStr(Temp2 + 1, L"%");
|
||||||
|
if (Temp2 == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Temp2 == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Temp2++;
|
||||||
|
CopyMem(Temp, Temp2, StrSize(Temp2));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Now cleanup any straggler intentionally ignored "%" characters
|
||||||
|
//
|
||||||
|
ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, L"^%", L"%", TRUE, FALSE);
|
||||||
|
StrCpy(NewCommandLine1, NewCommandLine2);
|
||||||
|
|
||||||
FreePool(NewCommandLine2);
|
FreePool(NewCommandLine2);
|
||||||
FreePool(ItemTemp);
|
FreePool(ItemTemp);
|
||||||
|
Reference in New Issue
Block a user