From: Jaben Carsey Date: Fri, 15 Nov 2013 18:39:26 +0000 (+0000) Subject: ShellPkg: verify that leading and trailing % are removed from variable names when... X-Git-Tag: edk2-stable201903~12108 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=6813ba402a7c52e80cc7aa4eb2a454a6b90ae011 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 Reviewed-by: Erik Bjorge git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14849 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c index 3564e06660..b6598c0cf4 100644 --- a/ShellPkg/Application/Shell/ShellParametersProtocol.c +++ b/ShellPkg/Application/Shell/ShellParametersProtocol.c @@ -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; } }