From: jcarsey Date: Fri, 11 Nov 2011 16:52:09 +0000 (+0000) Subject: Shellpkg: Add support for filenames with spaces. X-Git-Tag: edk2-stable201903~13920 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=031acf6336e92392966825b05600e4da1c24c655 Shellpkg: Add support for filenames with spaces. This patch changes the file redirection support to allow for quote delimited filenames that contain spaces and updates the edit command to allow spaces in the filename. This also properly fails for attempts to redirect to "" (empty quotes). This was missing from the first portion of the commit. signed-off-by: jcarsey reviewed-by: jliu66 git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12686 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c index 9e50225674..2d29ab1f2e 100644 --- a/ShellPkg/Application/Shell/ShellParametersProtocol.c +++ b/ShellPkg/Application/Shell/ShellParametersProtocol.c @@ -495,6 +495,46 @@ CalculateEfiHdrCrc ( Hdr->CRC32 = Crc; } +/** + Fix a string to only have the file name, removing starting at the first space of whatever is quoted. + + @param[in] FileName The filename to start with. + + @retval NULL FileName was invalid. + @return The modified FileName. +**/ +CHAR16* +EFIAPI +FixFileName ( + IN CHAR16 *FileName + ) +{ + CHAR16 *Copy; + CHAR16 *TempLocation; + + if (FileName == NULL) { + return (NULL); + } + + if (FileName[0] == L'\"') { + Copy = FileName+1; + if ((TempLocation = StrStr(Copy , L"\"")) != NULL) { + TempLocation[0] = CHAR_NULL; + } + } else { + Copy = FileName; + if ((TempLocation = StrStr(Copy , L" ")) != NULL) { + TempLocation[0] = CHAR_NULL; + } + } + + if (Copy[0] == CHAR_NULL) { + return (NULL); + } + + return (Copy); +} + /** Funcion will replace the current StdIn and StdOut in the ShellParameters protocol structure by parsing NewCommandLine. The current values are returned to the @@ -842,6 +882,11 @@ UpdateStdInStdOutStdErr( } } + // + // re-populate the string to support any filenames that were in quotes. + // + StrCpy(CommandLineCopy, NewCommandLine); + if (FirstLocation != CommandLineCopy + StrLen(CommandLineCopy) && ((UINTN)(FirstLocation - CommandLineCopy) < StrLen(NewCommandLine)) ){ @@ -849,23 +894,36 @@ UpdateStdInStdOutStdErr( } if (!EFI_ERROR(Status)) { - if (StdErrFileName != NULL && (CommandLineWalker = StrStr(StdErrFileName, L" ")) != NULL) { - CommandLineWalker[0] = CHAR_NULL; + + if (StdErrFileName != NULL) { + if ((StdErrFileName = FixFileName(StdErrFileName)) == NULL) { + Status = EFI_INVALID_PARAMETER; + } } - if (StdOutFileName != NULL && (CommandLineWalker = StrStr(StdOutFileName, L" ")) != NULL) { - CommandLineWalker[0] = CHAR_NULL; + if (StdOutFileName != NULL) { + if ((StdOutFileName = FixFileName(StdOutFileName)) == NULL) { + Status = EFI_INVALID_PARAMETER; + } } - if (StdInFileName != NULL && (CommandLineWalker = StrStr(StdInFileName , L" ")) != NULL) { - CommandLineWalker[0] = CHAR_NULL; + if (StdInFileName != NULL) { + if ((StdInFileName = FixFileName(StdInFileName)) == NULL) { + Status = EFI_INVALID_PARAMETER; + } } - if (StdErrVarName != NULL && (CommandLineWalker = StrStr(StdErrVarName , L" ")) != NULL) { - CommandLineWalker[0] = CHAR_NULL; + if (StdErrVarName != NULL) { + if ((StdErrVarName = FixFileName(StdErrVarName)) == NULL) { + Status = EFI_INVALID_PARAMETER; + } } - if (StdOutVarName != NULL && (CommandLineWalker = StrStr(StdOutVarName , L" ")) != NULL) { - CommandLineWalker[0] = CHAR_NULL; + if (StdOutVarName != NULL) { + if ((StdOutVarName = FixFileName(StdOutVarName)) == NULL) { + Status = EFI_INVALID_PARAMETER; + } } - if (StdInVarName != NULL && (CommandLineWalker = StrStr(StdInVarName , L" ")) != NULL) { - CommandLineWalker[0] = CHAR_NULL; + if (StdInVarName != NULL) { + if ((StdInVarName = FixFileName(StdInVarName)) == NULL) { + Status = EFI_INVALID_PARAMETER; + } } //