X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FApplication%2FShell%2FShellParametersProtocol.c;h=c8ac00bc813b4f4082d30d6731794e0ad46f5832;hb=f9aefb6a06acc93ac70c233a2e0552db9b3a68ce;hp=b90a2c32bbce2d076b713e0375a5db2f35b3a1f6;hpb=a1d4bfcc3f58a9ed0ce6118556016c7c058d01b1;p=mirror_edk2.git diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c index b90a2c32bb..c8ac00bc81 100644 --- a/ShellPkg/Application/Shell/ShellParametersProtocol.c +++ b/ShellPkg/Application/Shell/ShellParametersProtocol.c @@ -2,7 +2,7 @@ Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation, manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL. - Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -26,9 +26,9 @@ Temp Parameter must be large enough to hold the parameter before calling this function. - @param[in,out] Walker pointer to string of command line. Adjusted to + @param[in, out] Walker pointer to string of command line. Adjusted to reminaing command line on return - @param[in,out] TempParameter pointer to string of command line item extracted. + @param[in, out] TempParameter pointer to string of command line item extracted. **/ VOID @@ -69,9 +69,7 @@ GetNextParameter( if ((*Walker)[0] == L'\"') { NextDelim = NULL; for (TempLoc = *Walker + 1 ; TempLoc != NULL && *TempLoc != CHAR_NULL ; TempLoc++) { - if (*TempLoc == L'^' && *(TempLoc+1) == L'^') { - TempLoc++; - } else if (*TempLoc == L'^' && *(TempLoc+1) == L'\"') { + if (*TempLoc == L'^' && *(TempLoc+1) == L'\"') { TempLoc++; } else if (*TempLoc == L'\"') { NextDelim = TempLoc; @@ -96,10 +94,7 @@ GetNextParameter( *Walker = NULL; } for (TempLoc = *TempParameter ; TempLoc != NULL && *TempLoc != CHAR_NULL ; TempLoc++) { - if ((*TempLoc == L'^' && *(TempLoc+1) == L'^') - || (*TempLoc == L'^' && *(TempLoc+1) == L'|') - || (*TempLoc == L'^' && *(TempLoc+1) == L'\"') - ){ + if (*TempLoc == L'^' && *(TempLoc+1) == L'\"') { CopyMem(TempLoc, TempLoc+1, StrSize(TempLoc) - sizeof(TempLoc[0])); } } @@ -123,9 +118,7 @@ GetNextParameter( for (NextDelim = *TempParameter ; NextDelim != NULL && *NextDelim != CHAR_NULL ; NextDelim++) { if (*NextDelim == L'^' && *(NextDelim+1) == L'^') { CopyMem(NextDelim, NextDelim+1, StrSize(NextDelim) - sizeof(NextDelim[0])); - }/* else if (*NextDelim == L'^') { - *NextDelim = L' '; - }*/ + } } while ((*TempParameter)[StrLen(*TempParameter)-1] == L' ') { (*TempParameter)[StrLen(*TempParameter)-1] = CHAR_NULL; @@ -144,9 +137,9 @@ GetNextParameter( parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL. this supports space delimited and quote surrounded parameter definition. - @param[in] CommandLine String of command line to parse - @param[in,out] Argv pointer to array of strings; one for each parameter - @param[in,out] Argc pointer to number of strings in Argv array + @param[in] CommandLine String of command line to parse + @param[in, out] Argv pointer to array of strings; one for each parameter + @param[in, out] Argc pointer to number of strings in Argv array @return EFI_SUCCESS the operation was sucessful @return EFI_OUT_OF_RESOURCES a memory allocation failed. @@ -222,9 +215,9 @@ ParseCommandLineToArgs( installs it on our handle and if there is an existing version of the protocol that one is cached for removal later. - @param[in,out] NewShellParameters on a successful return, a pointer to pointer + @param[in, out] NewShellParameters on a successful return, a pointer to pointer to the newly installed interface. - @param[in,out] RootShellInstance on a successful return, pointer to boolean. + @param[in, out] RootShellInstance on a successful return, pointer to boolean. TRUE if this is the root shell instance. @retval EFI_SUCCESS the operation completed successfully. @@ -456,7 +449,7 @@ IsUnicodeFile( All of the characters between quotes is replaced with spaces. - @param[in,out] TheString A pointer to the string to update. + @param[in, out] TheString A pointer to the string to update. **/ VOID EFIAPI @@ -477,6 +470,74 @@ StripQuotes ( } } +/** + Calcualte the 32-bit CRC in a EFI table using the service provided by the + gRuntime service. + + @param Hdr Pointer to an EFI standard header + +**/ +VOID +CalculateEfiHdrCrc ( + IN OUT EFI_TABLE_HEADER *Hdr + ) +{ + UINT32 Crc; + + Hdr->CRC32 = 0; + + // + // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then + // Crc will come back as zero if we set it to zero here + // + Crc = 0; + gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc); + 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; + while(Copy[0] == L' ') { + Copy++; + } + 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 @@ -484,12 +545,12 @@ StripQuotes ( 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. - @param[out] OldStdIn Pointer to old StdIn. - @param[out] OldStdOut Pointer to old StdOut. - @param[out] OldStdErr Pointer to old StdErr. - @param[out] SystemTableInfo Pointer to old system table information. + @param[in, out] ShellParameters Pointer to parameter structure to modify. + @param[in] NewCommandLine The new command line to parse and use. + @param[out] OldStdIn Pointer to old StdIn. + @param[out] OldStdOut Pointer to old StdOut. + @param[out] OldStdErr Pointer to old StdErr. + @param[out] SystemTableInfo Pointer to old system table information. @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid. @retval EFI_OUT_OF_RESOURCES A memory allocation failed. @@ -559,6 +620,9 @@ UpdateStdInStdOutStdErr( } CommandLineCopy = StrnCatGrow(&CommandLineCopy, NULL, NewCommandLine, 0); + if (CommandLineCopy == NULL) { + return (EFI_OUT_OF_RESOURCES); + } Status = EFI_SUCCESS; Split = NULL; FirstLocation = CommandLineCopy + StrLen(CommandLineCopy); @@ -821,6 +885,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)) ){ @@ -828,23 +897,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; + } } // @@ -893,6 +975,9 @@ UpdateStdInStdOutStdErr( ||(StdErrFileName != NULL && !ErrUnicode && ErrAppend && (!EFI_ERROR(ShellFileExists(StdErrFileName)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName)))) ){ Status = EFI_INVALID_PARAMETER; + ShellParameters->StdIn = *OldStdIn; + ShellParameters->StdOut = *OldStdOut; + ShellParameters->StdErr = *OldStdErr; } else if (!EFI_ERROR(Status)){ // // Open the Std and we should not have conflicts here... @@ -1009,16 +1094,19 @@ UpdateStdInStdOutStdErr( // if (!EFI_ERROR(Status) && StdInVarName != NULL) { TempHandle = CreateFileInterfaceEnv(StdInVarName); - if (!InUnicode) { - TempHandle = CreateFileInterfaceFile(TempHandle, FALSE); - } - Size = 0; - ASSERT(TempHandle != NULL); - if (((EFI_FILE_PROTOCOL*)TempHandle)->Read(TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL) { - Status = EFI_INVALID_PARAMETER; + if (TempHandle == NULL) { + Status = EFI_OUT_OF_RESOURCES; } else { - ShellParameters->StdIn = TempHandle; - gST->ConIn = CreateSimpleTextInOnFile(TempHandle, &gST->ConsoleInHandle); + if (!InUnicode) { + TempHandle = CreateFileInterfaceFile(TempHandle, FALSE); + } + Size = 0; + if (TempHandle == NULL || ((EFI_FILE_PROTOCOL*)TempHandle)->Read(TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL) { + Status = EFI_INVALID_PARAMETER; + } else { + ShellParameters->StdIn = TempHandle; + gST->ConIn = CreateSimpleTextInOnFile(TempHandle, &gST->ConsoleInHandle); + } } } @@ -1043,6 +1131,8 @@ UpdateStdInStdOutStdErr( } FreePool(CommandLineCopy); + CalculateEfiHdrCrc(&gST->Hdr); + if (gST->ConIn == NULL ||gST->ConOut == NULL) { return (EFI_OUT_OF_RESOURCES); } @@ -1053,11 +1143,11 @@ UpdateStdInStdOutStdErr( Funcion will replace the current StdIn and StdOut in the ShellParameters protocol structure with StdIn and StdOut. The current values are de-allocated. - @param[in,out] ShellParameters Pointer to parameter structure to modify. - @param[in] OldStdIn Pointer to old StdIn. - @param[in] OldStdOut Pointer to old StdOut. - @param[in] OldStdErr Pointer to old StdErr. - @param[in] SystemTableInfo Pointer to old system table information. + @param[in, out] ShellParameters Pointer to parameter structure to modify. + @param[in] OldStdIn Pointer to old StdIn. + @param[in] OldStdOut Pointer to old StdOut. + @param[in] OldStdErr Pointer to old StdErr. + @param[in] SystemTableInfo Pointer to old system table information. **/ EFI_STATUS EFIAPI @@ -1116,6 +1206,8 @@ RestoreStdInStdOutStdErr ( gST->StandardErrorHandle = SystemTableInfo->ConErrHandle; } + CalculateEfiHdrCrc(&gST->Hdr); + return (EFI_SUCCESS); } /** @@ -1125,10 +1217,10 @@ RestoreStdInStdOutStdErr ( If OldArgv or OldArgc is NULL then that value is not returned. - @param[in,out] ShellParameters Pointer to parameter structure to modify. - @param[in] NewCommandLine The new command line to parse and use. - @param[out] OldArgv Pointer to old list of parameters. - @param[out] OldArgc Pointer to old number of items in Argv list. + @param[in, out] ShellParameters Pointer to parameter structure to modify. + @param[in] NewCommandLine The new command line to parse and use. + @param[out] OldArgv Pointer to old list of parameters. + @param[out] OldArgc Pointer to old number of items in Argv list. @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid. @retval EFI_OUT_OF_RESOURCES A memory allocation failed. @@ -1159,9 +1251,9 @@ UpdateArgcArgv( structure with Argv and Argc. The current values are de-allocated and the OldArgv must not be deallocated by the caller. - @param[in,out] ShellParameters pointer to parameter structure to modify - @param[in] OldArgv pointer to old list of parameters - @param[in] OldArgc pointer to old number of items in Argv list + @param[in, out] ShellParameters pointer to parameter structure to modify + @param[in] OldArgv pointer to old list of parameters + @param[in] OldArgc pointer to old number of items in Argv list **/ VOID EFIAPI