X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FApplication%2FShell%2FFileHandleWrappers.c;h=18b6c3e76829dfdf17ea595ea7c98241908d51e3;hb=4dc0d578b8b923672657956d3b1831c3cbf126ef;hp=2e1ce08ef3dfe53961ea98786ea779060d0cbd27;hpb=4ff7e37b4f7e336a8ecb7080b8f48eef4b52d396;p=mirror_edk2.git diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c b/ShellPkg/Application/Shell/FileHandleWrappers.c index 2e1ce08ef3..18b6c3e768 100644 --- a/ShellPkg/Application/Shell/FileHandleWrappers.c +++ b/ShellPkg/Application/Shell/FileHandleWrappers.c @@ -2,7 +2,8 @@ EFI_FILE_PROTOCOL wrappers for other items (Like Environment Variables, StdIn, StdOut, StdErr, etc...). - Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
+ (C) Copyright 2013 Hewlett-Packard Development Company, L.P.
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 @@ -416,7 +417,7 @@ FileInterfaceStdInRead( gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); if (EFI_ERROR (Status)) { - continue; + break; } // @@ -508,21 +509,24 @@ FileInterfaceStdInRead( if (StrStr(CurrentString + TabPos, L":") == NULL) { Cwd = ShellInfoObject.NewEfiShellProtocol->GetCurDir(NULL); if (Cwd != NULL) { - StrCpy(TabStr, Cwd); + StrnCpyS(TabStr, (*BufferSize)/sizeof(CHAR16), Cwd, (*BufferSize)/sizeof(CHAR16) - 1); if (TabStr[StrLen(TabStr)-1] == L'\\' && *(CurrentString + TabPos) == L'\\' ) { TabStr[StrLen(TabStr)-1] = CHAR_NULL; } - StrnCat(TabStr, CurrentString + TabPos, (StringLen - TabPos) * sizeof (CHAR16)); + StrnCatS( TabStr, + (*BufferSize)/sizeof(CHAR16), + CurrentString + TabPos, + StringLen - TabPos + ); } else { - StrCpy(TabStr, L""); - StrnCat(TabStr, CurrentString + TabPos, (StringLen - TabPos) * sizeof (CHAR16)); + *TabStr = CHAR_NULL; + StrnCatS(TabStr, (*BufferSize)/sizeof(CHAR16), CurrentString + TabPos, StringLen - TabPos); } } else { - StrCpy(TabStr, CurrentString + TabPos); + StrnCpyS(TabStr, (*BufferSize)/sizeof(CHAR16), CurrentString + TabPos, (*BufferSize)/sizeof(CHAR16) - 1); } - StrCat(TabStr, L"*"); + StrnCatS(TabStr, (*BufferSize)/sizeof(CHAR16), L"*", (*BufferSize)/sizeof(CHAR16) - 1 - StrLen(TabStr)); FoundFileList = NULL; -// TabStr = PathCleanUpDirectories(TabStr); Status = ShellInfoObject.NewEfiShellProtocol->FindFiles(TabStr, &FoundFileList); for ( TempStr = CurrentString ; *TempStr == L' ' @@ -848,7 +852,7 @@ FileInterfaceStdInRead( // ASSERT(FoundFileList == NULL); - return EFI_SUCCESS; + return Status; } // @@ -950,8 +954,48 @@ FileInterfaceEnvClose( IN EFI_FILE_PROTOCOL *This ) { + VOID* NewBuffer; + UINTN NewSize; + EFI_STATUS Status; + + // + // Most if not all UEFI commands will have an '\r\n' at the end of any output. + // Since the output was redirected to a variable, it does not make sense to + // keep this. So, before closing, strip the trailing '\r\n' from the variable + // if it exists. + // + NewBuffer = NULL; + NewSize = 0; + + Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer); + if (Status == EFI_BUFFER_TOO_SMALL) { + NewBuffer = AllocateZeroPool(NewSize + sizeof(CHAR16)); + if (NewBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer); + } + + if (!EFI_ERROR(Status) && NewBuffer != NULL) { + + if (StrSize(NewBuffer) > 6) + { + if ((((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 2] == CHAR_LINEFEED) + && (((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 3] == CHAR_CARRIAGE_RETURN)) { + ((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 3] = CHAR_NULL; + } + + if (IsVolatileEnv(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name)) { + Status = SHELL_SET_ENVIRONMENT_VARIABLE_V(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, StrSize(NewBuffer), NewBuffer); + } else { + Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, StrSize(NewBuffer), NewBuffer); + } + } + } + + SHELL_FREE_NON_NULL(NewBuffer); FreePool((EFI_FILE_PROTOCOL_ENVIRONMENT*)This); - return (EFI_SUCCESS); + return (Status); } /** @@ -1100,6 +1144,7 @@ CreateFileInterfaceEnv( ) { EFI_FILE_PROTOCOL_ENVIRONMENT *EnvFileInterface; + UINTN EnvNameSize; if (EnvName == NULL) { return (NULL); @@ -1108,7 +1153,8 @@ CreateFileInterfaceEnv( // // Get some memory // - EnvFileInterface = AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_ENVIRONMENT)+StrSize(EnvName)); + EnvNameSize = StrSize(EnvName); + EnvFileInterface = AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_ENVIRONMENT)+EnvNameSize); if (EnvFileInterface == NULL){ return (NULL); } @@ -1126,8 +1172,8 @@ CreateFileInterfaceEnv( EnvFileInterface->Flush = FileInterfaceNopGeneric; EnvFileInterface->Delete = FileInterfaceEnvDelete; EnvFileInterface->Read = FileInterfaceEnvRead; - - StrCpy(EnvFileInterface->Name, EnvName); + + CopyMem(EnvFileInterface->Name, EnvName, EnvNameSize); // // Assign the different members for Volatile and Non-Volatile variables @@ -1327,7 +1373,8 @@ FileInterfaceMemGetPosition( @param[in, out] BufferSize Size in bytes of Buffer. @param[in] Buffer The pointer to the buffer to write. - @retval EFI_SUCCESS The data was written. + @retval EFI_OUT_OF_RESOURCES The operation failed due to lack of resources. + @retval EFI_SUCCESS The data was written. **/ EFI_STATUS EFIAPI @@ -1354,6 +1401,9 @@ FileInterfaceMemWrite( // Ascii // AsciiBuffer = AllocateZeroPool(*BufferSize); + if (AsciiBuffer == NULL) { + return (EFI_OUT_OF_RESOURCES); + } AsciiSPrint(AsciiBuffer, *BufferSize, "%S", Buffer); if ((UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->Position + AsciiStrSize(AsciiBuffer)) > (UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize)) { ((EFI_FILE_PROTOCOL_MEM*)This)->Buffer = ReallocatePool((UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize), (UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize) + AsciiStrSize(AsciiBuffer) + 10, ((EFI_FILE_PROTOCOL_MEM*)This)->Buffer);