X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FApplication%2FShell%2FShell.c;h=ef821a5c5d021bc5ce20dfb8abb6ba37774af35b;hp=fcf4962e82560ca15a64393446e9d29a2369b806;hb=6fa0da7d52815979be31b8252aae839883dc7b0c;hpb=404b3f439492fac48207f5a8cb7ecc89f4287100 diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index fcf4962e82..ef821a5c5d 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -1596,6 +1596,96 @@ GetOperationType( return (UNKNOWN_INVALID); } +EFI_STATUS +EFIAPI +IsValidSplit( + IN CONST CHAR16 *CmdLine + ) +{ + CHAR16 *Temp; + CHAR16 *FirstParameter; + CHAR16 *TempWalker; + EFI_STATUS Status; + + Temp = NULL; + + Temp = StrnCatGrow(&Temp, NULL, CmdLine, 0); + if (Temp == NULL) { + return (EFI_OUT_OF_RESOURCES); + } + + FirstParameter = StrStr(Temp, L"|"); + if (FirstParameter != NULL) { + *FirstParameter = CHAR_NULL; + } + + FirstParameter = NULL; + + // + // Process the command line + // + Status = ProcessCommandLineToFinal(&Temp); + + if (!EFI_ERROR(Status)) { + FirstParameter = AllocateZeroPool(StrSize(CmdLine)); + if (FirstParameter == NULL) { + SHELL_FREE_NON_NULL(Temp); + return (EFI_OUT_OF_RESOURCES); + } + TempWalker = (CHAR16*)Temp; + GetNextParameter(&TempWalker, &FirstParameter); + + if (GetOperationType(FirstParameter) == UNKNOWN_INVALID) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter); + SetLastError(SHELL_NOT_FOUND); + Status = EFI_NOT_FOUND; + } + } + + SHELL_FREE_NON_NULL(Temp); + SHELL_FREE_NON_NULL(FirstParameter); + return Status; +} + +/** + Determine if a command line contains with a split contains only valid commands + + @param[in] CmdLine The command line to parse. + + @retval EFI_SUCCESS CmdLine has only valid commands, application, or has no split. + @retval EFI_ABORTED CmdLine has at least one invalid command or application. +**/ +EFI_STATUS +EFIAPI +VerifySplit( + IN CONST CHAR16 *CmdLine + ) +{ + CONST CHAR16 *TempSpot; + EFI_STATUS Status; + + // + // Verify up to the pipe or end character + // + Status = IsValidSplit(CmdLine); + if (EFI_ERROR(Status)) { + return (Status); + } + + // + // If this was the only item, then get out + // + if (!ContainsSplit(CmdLine)) { + return (EFI_SUCCESS); + } + + // + // recurse to verify the next item + // + TempSpot = FindSplit(CmdLine)+1; + return (VerifySplit(TempSpot)); +} + /** Process a split based operation. @@ -1613,6 +1703,11 @@ ProcessNewSplitCommandLine( SPLIT_LIST *Split; EFI_STATUS Status; + Status = VerifySplit(CmdLine); + if (EFI_ERROR(Status)) { + return (Status); + } + Split = NULL; // @@ -1728,7 +1823,7 @@ DoHelpUpdate( EFI_STATUS EFIAPI SetLastError( - IN CONST UINT64 ErrorCode + IN CONST SHELL_STATUS ErrorCode ) { CHAR16 LeString[19]; @@ -1754,7 +1849,7 @@ SetLastError( **/ EFI_STATUS EFIAPI -ProcessCommandLineAliasVariable( +ProcessCommandLineToFinal( IN OUT CHAR16 **CmdLine ) { @@ -1943,7 +2038,7 @@ RunCommandOrFile( // if (!EFI_ERROR(ShellIsDirectory(CommandWithPath))) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter); - SetLastError(EFI_NOT_FOUND); + SetLastError(SHELL_NOT_FOUND); } switch (Type) { case SCRIPT_FILE_NAME: @@ -1977,8 +2072,18 @@ RunCommandOrFile( // SetLastError(StatusCode); break; + default: + // + // Do nothing. + // + break; } break; + default: + // + // Do nothing. + // + break; } SHELL_FREE_NON_NULL(CommandWithPath); @@ -2086,7 +2191,7 @@ RunCommand( return (EFI_SUCCESS); } - Status = ProcessCommandLineAliasVariable(&CleanOriginal); + Status = ProcessCommandLineToFinal(&CleanOriginal); if (EFI_ERROR(Status)) { SHELL_FREE_NON_NULL(CleanOriginal); return (Status); @@ -2129,7 +2234,7 @@ RunCommand( // Whatever was typed, it was invalid. // ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter); - SetLastError(EFI_NOT_FOUND); + SetLastError(SHELL_NOT_FOUND); break; }