]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Fix ASCII input redirection does not work correctly.
authorQiu Shumin <shumin.qiu@intel.com>
Thu, 15 Oct 2015 02:43:31 +0000 (02:43 +0000)
committershenshushi <shenshushi@Edk2>
Thu, 15 Oct 2015 02:43:31 +0000 (02:43 +0000)
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

ShellPkg/Application/Shell/ConsoleWrappers.c
ShellPkg/Application/Shell/FileHandleWrappers.c
ShellPkg/Application/Shell/ShellParametersProtocol.c

index feea6ef3a22e58d89038398cbc7d88a3a2ab5171..04a7513a3346fabb272c70c58c74bfe184e7f190 100644 (file)
@@ -2,7 +2,7 @@
   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
@@ -15,6 +15,8 @@
 \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
@@ -81,6 +83,7 @@ FileBasedSimpleTextInReadKeyStroke(
   )\r
 {\r
   UINTN Size;\r
+  UINTN CharSize;\r
 \r
   //\r
   // Verify the parameters\r
@@ -98,11 +101,16 @@ FileBasedSimpleTextInReadKeyStroke(
 \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
index 18b6c3e76829dfdf17ea595ea7c98241908d51e3..91c35f7cb70a2e1eaf9561847afa94fb74ff4014 100644 (file)
@@ -1670,8 +1670,10 @@ FileInterfaceFileRead(
   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
@@ -1682,10 +1684,27 @@ FileInterfaceFileRead(
     //\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
index bbe026b644b27cc26262dfcd6b2be95ed97fa6f2..9c502f8f212e70290706b18c874b02582bb8fbb4 100644 (file)
@@ -17,6 +17,8 @@
 \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
@@ -726,6 +728,7 @@ UpdateStdInStdOutStdErr(
 \r
   OutUnicode      = TRUE;\r
   InUnicode       = TRUE;\r
+  AsciiRedirection = FALSE;\r
   ErrUnicode      = TRUE;\r
   StdInVarName    = NULL;\r
   StdOutVarName   = NULL;\r
@@ -1004,6 +1007,7 @@ UpdateStdInStdOutStdErr(
     } 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