ShellPkg: Fix ASCII input redirection does not work correctly.
When executing 'ls -b <a arg.txt' Shell cannot get the ASCII char in 'arg.txt' correctly. This patch updates the file read buffer size when read from ASCII file to fix the bug. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Qiu Shumin <shumin.qiu@intel.com> Signed-off-by: Felix Poludov <Felixp@ami.com> Signed-off-by: Oleksiy Yakovlev <Oleksiyy@ami.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18609 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@ -1670,8 +1670,10 @@ FileInterfaceFileRead(
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
CHAR8 *AsciiBuffer;
|
||||
CHAR8 *AsciiStrBuffer;
|
||||
CHAR16 *UscStrBuffer;
|
||||
UINTN Size;
|
||||
UINTN CharNum;
|
||||
EFI_STATUS Status;
|
||||
if (((EFI_FILE_PROTOCOL_FILE*)This)->Unicode) {
|
||||
//
|
||||
@ -1682,10 +1684,27 @@ FileInterfaceFileRead(
|
||||
//
|
||||
// Ascii
|
||||
//
|
||||
AsciiBuffer = AllocateZeroPool((Size = *BufferSize));
|
||||
Status = (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Read(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, &Size, AsciiBuffer));
|
||||
UnicodeSPrint(Buffer, *BufferSize, L"%a", AsciiBuffer);
|
||||
FreePool(AsciiBuffer);
|
||||
Size = (*BufferSize) / sizeof(CHAR16);
|
||||
AsciiStrBuffer = AllocateZeroPool(Size + sizeof(CHAR8));
|
||||
if (AsciiStrBuffer == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
UscStrBuffer = AllocateZeroPool(*BufferSize + sizeof(CHAR16));
|
||||
if (UscStrBuffer== NULL) {
|
||||
SHELL_FREE_NON_NULL(AsciiStrBuffer);
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
Status = (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Read(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, &Size, AsciiStrBuffer));
|
||||
if (!EFI_ERROR(Status)) {
|
||||
CharNum = UnicodeSPrint(UscStrBuffer, *BufferSize + sizeof(CHAR16), L"%a", AsciiStrBuffer);
|
||||
if (CharNum == Size) {
|
||||
CopyMem (Buffer, UscStrBuffer, *BufferSize);
|
||||
} else {
|
||||
Status = EFI_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
SHELL_FREE_NON_NULL(AsciiStrBuffer);
|
||||
SHELL_FREE_NON_NULL(UscStrBuffer);
|
||||
return (Status);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user