ShellPkg: Always remove non-defined environment variable

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <Jaben.carsey@intel.com>
Reviewed-by: Joe Peterson <joe.peterson@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hp.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16672 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Jaben Carsey 2015-01-27 18:53:27 +00:00 committed by jcarsey
parent 2bbbdc85a3
commit fdd52bde51

View File

@ -1,7 +1,7 @@
/** @file /** @file
This is THE shell (application) This is THE shell (application)
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P. (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -1381,8 +1381,8 @@ StripUnreplacedEnvironmentVariables(
break; break;
} }
if (FirstQuote < FirstPercent) { if (FirstQuote!= NULL && FirstQuote < FirstPercent) {
SecondQuote = FirstQuote!= NULL?FindNextInstance(FirstQuote+1, L"\"", TRUE):NULL; SecondQuote = FindNextInstance(FirstQuote+1, L"\"", TRUE);
// //
// Quote is first found // Quote is first found
// //
@ -1400,8 +1400,8 @@ StripUnreplacedEnvironmentVariables(
} }
continue; continue;
} }
ASSERT(FirstPercent < FirstQuote);
if (SecondPercent < FirstQuote) { if (FirstQuote == NULL || SecondPercent < FirstQuote) {
if (IsValidEnvironmentVariableName(FirstPercent, SecondPercent)) { if (IsValidEnvironmentVariableName(FirstPercent, SecondPercent)) {
// //
// We need to remove from FirstPercent to SecondPercent // We need to remove from FirstPercent to SecondPercent
@ -1415,7 +1415,6 @@ StripUnreplacedEnvironmentVariables(
} }
continue; continue;
} }
ASSERT(FirstQuote < SecondPercent);
CurrentLocator = FirstQuote; CurrentLocator = FirstQuote;
} }
return (EFI_SUCCESS); return (EFI_SUCCESS);
@ -1530,13 +1529,13 @@ ShellConvertVariables (
ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE); ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);
StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1); StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);
} }
//
// Remove non-existant environment variables in scripts only
//
StripUnreplacedEnvironmentVariables(NewCommandLine1);
} }
//
// Remove non-existant environment variables
//
StripUnreplacedEnvironmentVariables(NewCommandLine1);
// //
// Now cleanup any straggler intentionally ignored "%" characters // Now cleanup any straggler intentionally ignored "%" characters
// //