ShellPkg: verify that leading and trailing % are removed from variable names when doing command line redirection to an environment variable.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14849 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Jaben Carsey 2013-11-15 18:39:26 +00:00 committed by jcarsey
parent 4d0da5fb76
commit 6813ba402a
1 changed files with 32 additions and 3 deletions

View File

@ -538,6 +538,35 @@ FixFileName (
return (Copy);
}
/**
Fix a string to only have the environment variable name, removing starting at the first space of whatever is quoted and removing the leading and trailing %.
@param[in] FileName The filename to start with.
@retval NULL FileName was invalid.
@return The modified FileName.
**/
CHAR16*
EFIAPI
FixVarName (
IN CHAR16 *FileName
)
{
CHAR16 *Copy;
CHAR16 *TempLocation;
Copy = FileName;
if (FileName[0] == L'%') {
Copy = FileName+1;
if ((TempLocation = StrStr(Copy , L"%")) != NULL) {
TempLocation[0] = CHAR_NULL;
}
}
return (FixFileName(Copy));
}
/**
Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
structure by parsing NewCommandLine. The current values are returned to the
@ -914,17 +943,17 @@ UpdateStdInStdOutStdErr(
}
}
if (StdErrVarName != NULL) {
if ((StdErrVarName = FixFileName(StdErrVarName)) == NULL) {
if ((StdErrVarName = FixVarName(StdErrVarName)) == NULL) {
Status = EFI_INVALID_PARAMETER;
}
}
if (StdOutVarName != NULL) {
if ((StdOutVarName = FixFileName(StdOutVarName)) == NULL) {
if ((StdOutVarName = FixVarName(StdOutVarName)) == NULL) {
Status = EFI_INVALID_PARAMETER;
}
}
if (StdInVarName != NULL) {
if ((StdInVarName = FixFileName(StdInVarName)) == NULL) {
if ((StdInVarName = FixVarName(StdInVarName)) == NULL) {
Status = EFI_INVALID_PARAMETER;
}
}