mirror of
https://github.com/acidanthera/audk.git
synced 2025-04-08 17:05:09 +02:00
ShellPkg: Check the unrecognized environment variable name before it is removed from command line.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Qiu Shumin <shumin.qiu@intel.com> Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16563 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
5a2dcd134a
commit
4243567133
@ -142,6 +142,53 @@ FindNextInstance(
|
||||
return (Temp);
|
||||
}
|
||||
|
||||
/**
|
||||
Check whether the string between a pair of % is a valid envifronment variable name.
|
||||
|
||||
@param[in] BeginPercent pointer to the first percent.
|
||||
@param[in] EndPercent pointer to the last percent.
|
||||
|
||||
@retval TRUE is a valid environment variable name.
|
||||
@retval FALSE is NOT a valid environment variable name.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsValidEnvironmentVariableName(
|
||||
IN CONST CHAR16 *BeginPercent,
|
||||
IN CONST CHAR16 *EndPercent
|
||||
)
|
||||
{
|
||||
CONST CHAR16 *Walker;
|
||||
|
||||
Walker = NULL;
|
||||
|
||||
ASSERT (BeginPercent != NULL);
|
||||
ASSERT (EndPercent != NULL);
|
||||
ASSERT (BeginPercent < EndPercent);
|
||||
|
||||
if ((BeginPercent + 1) == EndPercent) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (Walker = BeginPercent + 1; Walker < EndPercent; Walker++) {
|
||||
if (
|
||||
(*Walker >= L'0' && *Walker <= L'9') ||
|
||||
(*Walker >= L'A' && *Walker <= L'Z') ||
|
||||
(*Walker >= L'a' && *Walker <= L'z') ||
|
||||
(*Walker == L'_')
|
||||
) {
|
||||
if (Walker == BeginPercent + 1 && (*Walker >= L'0' && *Walker <= L'9')) {
|
||||
return FALSE;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
Find a command line contains a split operation
|
||||
|
||||
@ -1355,14 +1402,17 @@ StripUnreplacedEnvironmentVariables(
|
||||
}
|
||||
ASSERT(FirstPercent < FirstQuote);
|
||||
if (SecondPercent < FirstQuote) {
|
||||
FirstPercent[0] = L'\"';
|
||||
SecondPercent[0] = L'\"';
|
||||
|
||||
//
|
||||
// We need to remove from FirstPercent to SecondPercent
|
||||
//
|
||||
CopyMem(FirstPercent + 1, SecondPercent, StrSize(SecondPercent));
|
||||
CurrentLocator = FirstPercent + 2;
|
||||
if (IsValidEnvironmentVariableName(FirstPercent, SecondPercent)) {
|
||||
//
|
||||
// We need to remove from FirstPercent to SecondPercent
|
||||
//
|
||||
CopyMem(FirstPercent, SecondPercent + 1, StrSize(SecondPercent + 1));
|
||||
//
|
||||
// dont need to update the locator. both % characters are gone.
|
||||
//
|
||||
} else {
|
||||
CurrentLocator = SecondPercent + 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
ASSERT(FirstQuote < SecondPercent);
|
||||
|
Loading…
x
Reference in New Issue
Block a user