diff options
Diffstat (limited to 'ShellPkg/Application/Shell/FileHandleWrappers.c')
-rw-r--r-- | ShellPkg/Application/Shell/FileHandleWrappers.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c b/ShellPkg/Application/Shell/FileHandleWrappers.c index 18b6c3e768..91c35f7cb7 100644 --- a/ShellPkg/Application/Shell/FileHandleWrappers.c +++ b/ShellPkg/Application/Shell/FileHandleWrappers.c @@ -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);
}
}
|