diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index ecd48cdd78..a56967189b 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -1427,21 +1427,6 @@ RunCommand( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle); } } else { - // - // remove the < and/or > from the command line now - // - for (TempLocation3 = PostVariableCmdLine ; TempLocation3 != NULL && *TempLocation3 != CHAR_NULL ; TempLocation3++) { - if (*TempLocation3 == L'^') { - if (*(TempLocation3+1) == L'<' || *(TempLocation3+1) == L'>') { - CopyMem(TempLocation3, TempLocation3+1, StrSize(TempLocation3) - sizeof(TempLocation3[0])); - } - } else if (*TempLocation3 == L'>') { - *TempLocation3 = CHAR_NULL; - } else if ((*TempLocation3 == L'1' || *TempLocation3 == L'2')&&(*(TempLocation3+1) == L'>')) { - *TempLocation3 = CHAR_NULL; - } - } - while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') { PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL; } diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c index 3d138825ff..de2d4d1220 100644 --- a/ShellPkg/Application/Shell/ShellParametersProtocol.c +++ b/ShellPkg/Application/Shell/ShellParametersProtocol.c @@ -73,10 +73,6 @@ GetNextParameter( TempLoc++; } else if (*TempLoc == L'^' && *(TempLoc+1) == L'\"') { TempLoc++; - } else if (*TempLoc == L'^' && *(TempLoc+1) == L'|') { - TempLoc++; - } else if (*TempLoc == L'^') { - *TempLoc = L' '; } else if (*TempLoc == L'\"') { NextDelim = TempLoc; break; @@ -447,6 +443,30 @@ IsUnicodeFile( return (Status); } +/** + Strips out quotes sections of a string. + + All of the characters between quotes is replaced with spaces. +**/ +VOID +EFIAPI +StripQuotes ( + IN OUT CHAR16 *TheString + ) +{ + BOOLEAN RemoveNow; + + for (RemoveNow = FALSE ; TheString != NULL && *TheString != CHAR_NULL ; TheString++) { + if (*TheString == L'^' && *(TheString + 1) == L'\"') { + TheString++; + } else if (*TheString == L'\"') { + RemoveNow = (BOOLEAN)!RemoveNow; + } else if (RemoveNow) { + *TheString = L' '; + } + } +} + /** Funcion will replace the current StdIn and StdOut in the ShellParameters protocol structure by parsing NewCommandLine. The current values are returned to the @@ -468,7 +488,7 @@ EFI_STATUS EFIAPI UpdateStdInStdOutStdErr( IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters, - IN CONST CHAR16 *NewCommandLine, + IN CHAR16 *NewCommandLine, OUT SHELL_FILE_HANDLE *OldStdIn, OUT SHELL_FILE_HANDLE *OldStdOut, OUT SHELL_FILE_HANDLE *OldStdErr, @@ -494,6 +514,7 @@ UpdateStdInStdOutStdErr( UINTN Size; CHAR16 TagBuffer[2]; SPLIT_LIST *Split; + CHAR16 *FirstLocation; OutUnicode = TRUE; InUnicode = TRUE; @@ -507,6 +528,7 @@ UpdateStdInStdOutStdErr( ErrAppend = FALSE; OutAppend = FALSE; CommandLineCopy = NULL; + FirstLocation = (CHAR16*)(-1); if (ShellParameters == NULL || SystemTableInfo == NULL || OldStdIn == NULL || OldStdOut == NULL || OldStdErr == NULL) { return (EFI_INVALID_PARAMETER); @@ -530,6 +552,8 @@ UpdateStdInStdOutStdErr( Status = EFI_SUCCESS; Split = NULL; + StripQuotes(CommandLineCopy); + if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) { Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link); if (Split != NULL && Split->SplitStdIn != NULL) { @@ -541,6 +565,7 @@ UpdateStdInStdOutStdErr( } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>>v ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 12, L' '); StdErrVarName = CommandLineWalker += 6; ErrAppend = TRUE; @@ -549,6 +574,7 @@ UpdateStdInStdOutStdErr( } } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>v ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 12, L' '); StdOutVarName = CommandLineWalker += 6; OutAppend = TRUE; @@ -556,6 +582,7 @@ UpdateStdInStdOutStdErr( Status = EFI_NOT_FOUND; } } else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>v ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 10, L' '); StdOutVarName = CommandLineWalker += 5; OutAppend = TRUE; @@ -563,6 +590,7 @@ UpdateStdInStdOutStdErr( Status = EFI_NOT_FOUND; } } else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >v ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 8, L' '); StdOutVarName = CommandLineWalker += 4; OutAppend = FALSE; @@ -571,6 +599,7 @@ UpdateStdInStdOutStdErr( } } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>a ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 12, L' '); StdOutFileName = CommandLineWalker += 6; OutAppend = TRUE; @@ -580,6 +609,7 @@ UpdateStdInStdOutStdErr( } } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>> ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 10, L' '); if (StdOutFileName != NULL) { Status = EFI_INVALID_PARAMETER; @@ -592,6 +622,7 @@ UpdateStdInStdOutStdErr( } } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >> ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 8, L' '); if (StdOutFileName != NULL) { Status = EFI_INVALID_PARAMETER; @@ -604,6 +635,7 @@ UpdateStdInStdOutStdErr( } } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>a ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 10, L' '); if (StdOutFileName != NULL) { Status = EFI_INVALID_PARAMETER; @@ -617,6 +649,7 @@ UpdateStdInStdOutStdErr( } } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>a ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 10, L' '); if (StdOutFileName != NULL) { Status = EFI_INVALID_PARAMETER; @@ -630,6 +663,7 @@ UpdateStdInStdOutStdErr( } } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >a ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 8, L' '); if (StdOutFileName != NULL) { Status = EFI_INVALID_PARAMETER; @@ -643,6 +677,7 @@ UpdateStdInStdOutStdErr( } } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>> ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 10, L' '); if (StdErrFileName != NULL) { Status = EFI_INVALID_PARAMETER; @@ -656,6 +691,7 @@ UpdateStdInStdOutStdErr( } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>v ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 10, L' '); if (StdErrVarName != NULL) { Status = EFI_INVALID_PARAMETER; @@ -668,6 +704,7 @@ UpdateStdInStdOutStdErr( } } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>v ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 10, L' '); if (StdOutVarName != NULL) { Status = EFI_INVALID_PARAMETER; @@ -680,6 +717,7 @@ UpdateStdInStdOutStdErr( } } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>a ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 10, L' '); if (StdErrFileName != NULL) { Status = EFI_INVALID_PARAMETER; @@ -693,6 +731,7 @@ UpdateStdInStdOutStdErr( } } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2> ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 8, L' '); if (StdErrFileName != NULL) { Status = EFI_INVALID_PARAMETER; @@ -706,6 +745,7 @@ UpdateStdInStdOutStdErr( } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1> ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 8, L' '); if (StdOutFileName != NULL) { Status = EFI_INVALID_PARAMETER; @@ -719,6 +759,7 @@ UpdateStdInStdOutStdErr( } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" > ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 6, L' '); if (StdOutFileName != NULL) { Status = EFI_INVALID_PARAMETER; @@ -732,6 +773,7 @@ UpdateStdInStdOutStdErr( } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" < ")) != NULL) { + FirstLocation = MIN(CommandLineWalker, FirstLocation); SetMem16(CommandLineWalker, 6, L' '); if (StdInFileName != NULL) { Status = EFI_INVALID_PARAMETER; @@ -743,6 +785,7 @@ UpdateStdInStdOutStdErr( } } if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" or < - // - ||(StrStr(CommandLineCopy, L"<") != NULL) - ||(StrStr(CommandLineCopy, L">") != NULL) - // // Check for no volatile environment variables // ||(StdErrVarName != NULL && !IsVolatileEnv(StdErrVarName)) @@ -837,7 +879,7 @@ UpdateStdInStdOutStdErr( ||(StdErrFileName != NULL && !ErrUnicode && ErrAppend && (!EFI_ERROR(ShellFileExists(StdErrFileName)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName)))) ){ Status = EFI_INVALID_PARAMETER; - } else { + } else if (!EFI_ERROR(Status)){ // // Open the Std and we should not have conflicts here... // diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.h b/ShellPkg/Application/Shell/ShellParametersProtocol.h index 2d19587610..df3bfa7cbc 100644 --- a/ShellPkg/Application/Shell/ShellParametersProtocol.h +++ b/ShellPkg/Application/Shell/ShellParametersProtocol.h @@ -132,7 +132,7 @@ typedef struct { structure by parsing NewCommandLine. The current values are returned to the user. - If OldStdIn or OldStdOut is NULL then that value is not returned. + This will also update the system table. @param[in,out] ShellParameters Pointer to parameter structure to modify. @param[in] NewCommandLine The new command line to parse and use. @@ -148,7 +148,7 @@ EFI_STATUS EFIAPI UpdateStdInStdOutStdErr( IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters, - IN CONST CHAR16 *NewCommandLine, + IN CHAR16 *NewCommandLine, OUT SHELL_FILE_HANDLE *OldStdIn, OUT SHELL_FILE_HANDLE *OldStdOut, OUT SHELL_FILE_HANDLE *OldStdErr,