X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FApplication%2FShell%2FShell.c;h=2adc99240c483f01e5282002122028e5df842e15;hb=e7275d3ffd410943479a9658707ab04d3e9f75ba;hp=5a941aabd0c9f8bc7da7a78a33ebfe634456dea9;hpb=3efa3f3d05ea3fef964e59aea9b5792cfec348ed;p=mirror_edk2.git diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index 5a941aabd0..2adc99240c 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -726,6 +726,7 @@ FreeResources: **/ EFI_STATUS SetBuiltInAlias( + VOID ) { EFI_STATUS Status; @@ -1162,6 +1163,12 @@ LocateStartupScript ( MapName = ShellInfoObject.NewEfiShellProtocol->GetMapFromDevicePath (&ImageDevicePath); if (MapName != NULL) { StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, MapName, 0); + if (StartupScriptPath == NULL) { + // + // Do not locate the startup script in sys path when out of resource. + // + return NULL; + } TempSpot = StrStr (StartupScriptPath, L";"); if (TempSpot != NULL) { *TempSpot = CHAR_NULL; @@ -1273,6 +1280,11 @@ DoStartupScript( if (FileStringPath != NULL) { Status = RunScriptFile (FileStringPath, NULL, L"", ShellInfoObject.NewShellParametersProtocol); FreePool (FileStringPath); + } else { + // + // we return success since startup script is not mandatory. + // + Status = EFI_SUCCESS; } return (Status); @@ -1635,7 +1647,7 @@ ShellConvertVariables ( // // now do the replacements... // - NewCommandLine1 = AllocateCopyPool(NewSize, OriginalCommandLine); + NewCommandLine1 = AllocateZeroPool (NewSize); NewCommandLine2 = AllocateZeroPool(NewSize); ItemTemp = AllocateZeroPool(ItemSize+(2*sizeof(CHAR16))); if (NewCommandLine1 == NULL || NewCommandLine2 == NULL || ItemTemp == NULL) { @@ -1644,6 +1656,8 @@ ShellConvertVariables ( SHELL_FREE_NON_NULL(ItemTemp); return (NULL); } + CopyMem (NewCommandLine1, OriginalCommandLine, StrSize (OriginalCommandLine)); + for (MasterEnvList = EfiShellGetEnv(NULL) ; MasterEnvList != NULL && *MasterEnvList != CHAR_NULL ; MasterEnvList += StrLen(MasterEnvList) + 1 @@ -1703,8 +1717,8 @@ ShellConvertVariables ( EFI_STATUS RunSplitCommand( IN CONST CHAR16 *CmdLine, - IN SHELL_FILE_HANDLE *StdIn, - IN SHELL_FILE_HANDLE *StdOut + IN SHELL_FILE_HANDLE StdIn, + IN SHELL_FILE_HANDLE StdOut ) { EFI_STATUS Status; @@ -1713,7 +1727,7 @@ RunSplitCommand( UINTN Size1; UINTN Size2; SPLIT_LIST *Split; - SHELL_FILE_HANDLE *TempFileHandle; + SHELL_FILE_HANDLE TempFileHandle; BOOLEAN Unicode; ASSERT(StdOut == NULL); @@ -1779,7 +1793,7 @@ RunSplitCommand( Split->SplitStdOut = Split->SplitStdIn; } Split->SplitStdIn = TempFileHandle; - ShellInfoObject.NewEfiShellProtocol->SetFilePosition(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn), 0); + ShellInfoObject.NewEfiShellProtocol->SetFilePosition (Split->SplitStdIn, 0); if (!EFI_ERROR(Status)) { Status = RunCommand(NextCommandLine); @@ -1795,11 +1809,10 @@ RunSplitCommand( // Note that the original StdIn is now the StdOut... // if (Split->SplitStdOut != NULL) { - ShellInfoObject.NewEfiShellProtocol->CloseFile(ConvertShellHandleToEfiFileProtocol(Split->SplitStdOut)); + ShellInfoObject.NewEfiShellProtocol->CloseFile (Split->SplitStdOut); } if (Split->SplitStdIn != NULL) { - ShellInfoObject.NewEfiShellProtocol->CloseFile(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn)); - FreePool (Split->SplitStdIn); + ShellInfoObject.NewEfiShellProtocol->CloseFile (Split->SplitStdIn); } FreePool(Split); @@ -2604,6 +2617,7 @@ RunShellCommand( CHAR16 *FirstParameter; CHAR16 *TempWalker; SHELL_OPERATION_TYPES Type; + CONST CHAR16 *CurDir; ASSERT(CmdLine != NULL); if (StrLen(CmdLine) == 0) { @@ -2695,7 +2709,22 @@ RunShellCommand( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter); SetLastError(SHELL_NOT_FOUND); } - + // + // Check whether the current file system still exists. If not exist, we need update "cwd" and gShellCurMapping. + // + CurDir = EfiShellGetCurDir (NULL); + if (CurDir != NULL) { + if (EFI_ERROR(ShellFileExists (CurDir))) { + // + // EfiShellSetCurDir() cannot set current directory to NULL. + // EfiShellSetEnv() is not allowed to set the "cwd" variable. + // Only InternalEfiShellSetEnv () is allowed setting the "cwd" variable. + // + InternalEfiShellSetEnv (L"cwd", NULL, TRUE); + gShellCurMapping = NULL; + } + } + SHELL_FREE_NON_NULL(CleanOriginal); SHELL_FREE_NON_NULL(FirstParameter);