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
Function definitions for shell simple text in and out on top of file handles.\r
\r
(C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>\r
- Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
\r
#include "Shell.h"\r
\r
+extern BOOLEAN AsciiRedirection;\r
+\r
typedef struct {\r
EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn;\r
SHELL_FILE_HANDLE FileHandle;\r
)\r
{\r
UINTN Size;\r
+ UINTN CharSize;\r
\r
//\r
// Verify the parameters\r
\r
Size = sizeof(CHAR16);\r
\r
+ if(!AsciiRedirection) {\r
+ CharSize = sizeof(CHAR16);\r
+ } else {\r
+ CharSize = sizeof(CHAR8);\r
+ } \r
//\r
// Decrement the amount of free space by Size or set to zero (for odd length files)\r
//\r
- if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile > Size) {\r
- ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile -= Size;\r
+ if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile > CharSize) {\r
+ ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile -= CharSize;\r
} else {\r
((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile = 0;\r
}\r
OUT VOID *Buffer\r
)\r
{\r
- CHAR8 *AsciiBuffer;\r
+ CHAR8 *AsciiStrBuffer;\r
+ CHAR16 *UscStrBuffer;\r
UINTN Size;\r
+ UINTN CharNum;\r
EFI_STATUS Status;\r
if (((EFI_FILE_PROTOCOL_FILE*)This)->Unicode) {\r
//\r
//\r
// Ascii\r
//\r
- AsciiBuffer = AllocateZeroPool((Size = *BufferSize));\r
- Status = (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Read(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, &Size, AsciiBuffer));\r
- UnicodeSPrint(Buffer, *BufferSize, L"%a", AsciiBuffer);\r
- FreePool(AsciiBuffer);\r
+ Size = (*BufferSize) / sizeof(CHAR16);\r
+ AsciiStrBuffer = AllocateZeroPool(Size + sizeof(CHAR8));\r
+ if (AsciiStrBuffer == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ UscStrBuffer = AllocateZeroPool(*BufferSize + sizeof(CHAR16));\r
+ if (UscStrBuffer== NULL) {\r
+ SHELL_FREE_NON_NULL(AsciiStrBuffer);\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ Status = (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Read(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, &Size, AsciiStrBuffer));\r
+ if (!EFI_ERROR(Status)) {\r
+ CharNum = UnicodeSPrint(UscStrBuffer, *BufferSize + sizeof(CHAR16), L"%a", AsciiStrBuffer);\r
+ if (CharNum == Size) {\r
+ CopyMem (Buffer, UscStrBuffer, *BufferSize);\r
+ } else {\r
+ Status = EFI_UNSUPPORTED;\r
+ }\r
+ }\r
+ SHELL_FREE_NON_NULL(AsciiStrBuffer);\r
+ SHELL_FREE_NON_NULL(UscStrBuffer);\r
return (Status);\r
}\r
}\r
\r
#include "Shell.h"\r
\r
+BOOLEAN AsciiRedirection = FALSE;\r
+\r
/**\r
Return the next parameter's end from a command line string.\r
\r
\r
OutUnicode = TRUE;\r
InUnicode = TRUE;\r
+ AsciiRedirection = FALSE;\r
ErrUnicode = TRUE;\r
StdInVarName = NULL;\r
StdOutVarName = NULL;\r
} else {\r
StdInFileName = CommandLineWalker += 4;\r
InUnicode = FALSE;\r
+ AsciiRedirection = TRUE;\r
}\r
if (StrStr(CommandLineWalker, L" <a ") != NULL) {\r
Status = EFI_NOT_FOUND;\r