summaryrefslogtreecommitdiff
path: root/ShellPkg
diff options
context:
space:
mode:
authorJaben Carsey <Jaben.carsey@intel.com>2013-08-21 18:11:23 +0000
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2013-08-21 18:11:23 +0000
commitdf07baea2f9d1e40bd8fb3e445286d231241023a (patch)
treec628eca61590287a468b3555b589c662609bb126 /ShellPkg
parentac8783c8b162b9a3b1e2da222cf6d088fcf63cfb (diff)
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
Diffstat (limited to 'ShellPkg')
-rw-r--r--ShellPkg/Application/Shell/Shell.c53
1 files changed, 44 insertions, 9 deletions
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c
index 00c7bb58c..3df55e1a1 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -1085,6 +1085,7 @@ ShellConvertVariables (
CHAR16 *NewCommandLine1;
CHAR16 *NewCommandLine2;
CHAR16 *Temp;
+ CHAR16 *Temp2;
UINTN ItemSize;
CHAR16 *ItemTemp;
SCRIPT_FILE *CurrentScriptFile;
@@ -1143,15 +1144,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...
//
NewCommandLine1 = AllocateZeroPool(NewSize);
@@ -1182,8 +1174,51 @@ ShellConvertVariables (
ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);
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(ItemTemp);