diff options
author | Qiu Shumin <shumin.qiu@intel.com> | 2014-12-31 01:31:00 +0000 |
---|---|---|
committer | shenshushi <shenshushi@Edk2> | 2014-12-31 01:31:00 +0000 |
commit | 42435671334345f91e7cb2e5e963ed457fbb61d6 (patch) | |
tree | 74467ec2316f3ce3c2f9a022e3c94f6bdff764ee /ShellPkg/Application/Shell/Shell.c | |
parent | 5a2dcd134a23491148af21792cec45252996d0d9 (diff) | |
download | edk2-platforms-42435671334345f91e7cb2e5e963ed457fbb61d6.tar.xz |
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
Diffstat (limited to 'ShellPkg/Application/Shell/Shell.c')
-rw-r--r-- | ShellPkg/Application/Shell/Shell.c | 66 |
1 files changed, 58 insertions, 8 deletions
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index de46a72b44..695880197b 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -143,6 +143,53 @@ FindNextInstance( }
/**
+ 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
@param[in] CmdLine The command line to parse.
@@ -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);
|