Andrew Fish, Yes,some times I am work in C++,thanks for correct this,but if I use this: UINT16 Buffer[80*25*4]; //tool's buffer; UINTN BufferByteSize = sizeof(Buffer); it still cannot work. I had checked the read size( gShell->ReadFile(gParameters->StdIn,...)) before I post my question,it just read some hundred of bytes,It seems the question is not about overflow... so I want to know if I'm wrong or it is a bug?
thank you, by krishna. At 2018-07-04 22:55:27, "Andrew Fish" <[email protected]> wrote: >Krishnal, > >Thanks for including the code. You are overflowing the buffer. In C >sizeof(Buffer) will be 80*25*4*2 since sizeof(UINT16) is 2. Your code is >passing in double the size of the buffer. > >UINT16 Buffer[80*25*4]; //tool's buffer; >UINTN BufferSize=sizeof(Buffer); >UINTN BufferByteSize=BufferSize*sizeof(UINT16); > >This should work: > >UINT16 Buffer[80*25*4]; //tool's buffer; >UINTN BufferByteSize = sizeof(Buffer); > >Thanks, > >Andrew Fish > >> On Jul 4, 2018, at 2:15 AM, krishnaLee <[email protected]> wrote: >> >> Hi, >> I wrote this shell application(smalltest.efi),did some pipe function >> test,find some strange result. >> boot into shell: >> >> >> # test-1,the follow two command should has the same output ,but infact not >> the same in QEMU,and the second command failed WriteFile in real machine(AMI >> bios uefi 2.6): >> ls | smalltest.efi >> ls | smalltest.efi | smalltest.efi # the ls command directory >> only has one file(this tool),so the tool's buffer 80x25*4 won't overflow. >> >> >> #test-2 >> run smalltest.efi, >> just key in some chars and Enter,nothing output,why? >> >> >> my test environment: >> UDK2018 + vs2015 >> QEMU emulator version 2.10.95 >> OVMF_X64.fd( x64,release build) >> >> >> the tool's build command: >> D:\edk2-vUDK2018>build -p ShellPkg\ShellPkg.dsc -m >> ShellPkg\Application2\smalltest\smalltest.inf -a X64 -b RELEASE >> >> >> //--------code---smalltest.c------------- >> >> >> #include <Uefi.h> >> #include <Library/UefiApplicationEntryPoint.h> >> #include <Library/UefiLib.h> >> #include <Library/UefiBootServicesTableLib.h>//global gST gBS gImageHandle >> #include <Library/BaseMemoryLib.h> >> #include <Library/MemoryAllocationLib.h> >> >> >> #include <Protocol/Shell.h> >> #include <Protocol/ShellParameters.h> >> >> >> >> EFI_STATUS >> EFIAPI >> UefiMain ( >> IN EFI_HANDLE ImageHandle, >> IN EFI_SYSTEM_TABLE *SystemTable >> ) >> { >> EFI_STATUS status; >> EFI_SHELL_PROTOCOL* gShell; >> EFI_SHELL_PARAMETERS_PROTOCOL*gParameters; >> UINT16 Buffer[80*25*4]; //tool's buffer; >> UINTN BufferSize=sizeof(Buffer); >> UINTN BufferByteSize=BufferSize*sizeof(UINT16); >> >> >> status=gBS->HandleProtocol(gImageHandle,&gEfiShellParametersProtocolGuid,&gParameters); >> if(status!=EFI_SUCCESS) >> { >> Print(L"locate gEfiShellParametersProtocolGuid failed.\n"); >> return status; >> } >> >> >> status=gBS->LocateProtocol(&gEfiShellProtocolGuid,NULL,&gShell); >> if(status!=EFI_SUCCESS) >> { >> Print(L"locate gEfiShellProtocolGuid failed.\n"); >> return status; >> } >> >> >> status=gShell->ReadFile(gParameters->StdIn,&BufferByteSize,(VOID*)Buffer); >> if(status!=EFI_SUCCESS) >> { >> Print(L"read from gParameters->StdIn failed.\n"); >> return status; >> } >> >> >> status=gShell->WriteFile(gParameters->StdOut,&BufferByteSize,(VOID*)Buffer); >> if(status!=EFI_SUCCESS) >> { >> Print(L"wirte gParameters->StdOut failed\n"); >> return status; >> } >> >> >> gShell->FlushFile(gParameters->StdOut); >> >> >> return EFI_SUCCESS; >> } >> >> >> //--------code---smalltest.inf------------- >> >> >> [Defines] >> INF_VERSION = 0x00010005 >> BASE_NAME = smalltest >> FILE_GUID = 8F7D7B1D-0E1C-4c98-B12E-4EC99C400704 >> MODULE_TYPE = UEFI_APPLICATION >> VERSION_STRING = 1.0 >> ENTRY_POINT = UefiMain >> >> >> [Sources] >> smalltest.c >> >> >> [Packages] >> MdePkg/MdePkg.dec >> >> >> [Protocols] >> gEfiShellProtocolGuid >> gEfiShellParametersProtocolGuid >> >> >> [LibraryClasses] >> UefiApplicationEntryPoint >> UefiLib >> //--------code---end---------------------------------------------------------- >> >> >> >> >> >> >> thank you, >> by krishna. >> _______________________________________________ >> edk2-devel mailing list >> [email protected] >> https://lists.01.org/mailman/listinfo/edk2-devel _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

