summaryrefslogtreecommitdiff
path: root/ShellPkg/Application
diff options
context:
space:
mode:
authorQiu Shumin <shumin.qiu@intel.com>2015-12-18 07:29:05 +0000
committervanjeff <vanjeff@Edk2>2015-12-18 07:29:05 +0000
commit90fb9ed5a0d24117a4847b5d25bca84d8d90c5c2 (patch)
tree6c6a4bbf4c37900b225e6be13576948dd12ebff0 /ShellPkg/Application
parentbd8504381c8acf81d4abfe252751a2d93ae97d0d (diff)
downloadedk2-platforms-90fb9ed5a0d24117a4847b5d25bca84d8d90c5c2.tar.xz
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. (Sync patch r18609 from main trunk.) 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/branches/UDK2015@19394 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg/Application')
-rw-r--r--ShellPkg/Application/Shell/ConsoleWrappers.c14
-rw-r--r--ShellPkg/Application/Shell/FileHandleWrappers.c29
-rw-r--r--ShellPkg/Application/Shell/ShellParametersProtocol.c4
3 files changed, 39 insertions, 8 deletions
diff --git a/ShellPkg/Application/Shell/ConsoleWrappers.c b/ShellPkg/Application/Shell/ConsoleWrappers.c
index feea6ef3a2..04a7513a33 100644
--- a/ShellPkg/Application/Shell/ConsoleWrappers.c
+++ b/ShellPkg/Application/Shell/ConsoleWrappers.c
@@ -2,7 +2,7 @@
Function definitions for shell simple text in and out on top of file handles.
(C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>
- Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
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
@@ -15,6 +15,8 @@
#include "Shell.h"
+extern BOOLEAN AsciiRedirection;
+
typedef struct {
EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn;
SHELL_FILE_HANDLE FileHandle;
@@ -81,6 +83,7 @@ FileBasedSimpleTextInReadKeyStroke(
)
{
UINTN Size;
+ UINTN CharSize;
//
// Verify the parameters
@@ -98,11 +101,16 @@ FileBasedSimpleTextInReadKeyStroke(
Size = sizeof(CHAR16);
+ if(!AsciiRedirection) {
+ CharSize = sizeof(CHAR16);
+ } else {
+ CharSize = sizeof(CHAR8);
+ }
//
// Decrement the amount of free space by Size or set to zero (for odd length files)
//
- if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile > Size) {
- ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile -= Size;
+ if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile > CharSize) {
+ ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile -= CharSize;
} else {
((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile = 0;
}
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);
}
}
diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c
index bbe026b644..9c502f8f21 100644
--- a/ShellPkg/Application/Shell/ShellParametersProtocol.c
+++ b/ShellPkg/Application/Shell/ShellParametersProtocol.c
@@ -17,6 +17,8 @@
#include "Shell.h"
+BOOLEAN AsciiRedirection = FALSE;
+
/**
Return the next parameter's end from a command line string.
@@ -726,6 +728,7 @@ UpdateStdInStdOutStdErr(
OutUnicode = TRUE;
InUnicode = TRUE;
+ AsciiRedirection = FALSE;
ErrUnicode = TRUE;
StdInVarName = NULL;
StdOutVarName = NULL;
@@ -1004,6 +1007,7 @@ UpdateStdInStdOutStdErr(
} else {
StdInFileName = CommandLineWalker += 4;
InUnicode = FALSE;
+ AsciiRedirection = TRUE;
}
if (StrStr(CommandLineWalker, L" <a ") != NULL) {
Status = EFI_NOT_FOUND;