Revision: 14585
          http://sourceforge.net/p/edk2/code/14585
Author:   jcarsey
Date:     2013-08-21 18:11:23 +0000 (Wed, 21 Aug 2013)
Log Message:
-----------
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.car...@intel.com>
reviewed-by: Matthews, Robert <robert.matth...@hp.com>

Modified Paths:
--------------
    trunk/edk2/ShellPkg/Application/Shell/Shell.c

Modified: trunk/edk2/ShellPkg/Application/Shell/Shell.c
===================================================================
--- trunk/edk2/ShellPkg/Application/Shell/Shell.c       2013-08-21 17:32:16 UTC 
(rev 14584)
+++ trunk/edk2/ShellPkg/Application/Shell/Shell.c       2013-08-21 18:11:23 UTC 
(rev 14585)
@@ -1085,6 +1085,7 @@
   CHAR16              *NewCommandLine1;
   CHAR16              *NewCommandLine2;
   CHAR16              *Temp;
+  CHAR16              *Temp2;
   UINTN               ItemSize;
   CHAR16              *ItemTemp;
   SCRIPT_FILE         *CurrentScriptFile;
@@ -1143,15 +1144,6 @@
   }
 
   //
-  // 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 @@
     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);
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
edk2-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to