summaryrefslogtreecommitdiff
path: root/ShellPkg/Library/UefiShellLib
diff options
context:
space:
mode:
authorjaben carsey <jaben.carsey@intel.com>2016-02-08 15:59:04 -0800
committerHao Wu <hao.a.wu@intel.com>2016-07-13 20:41:54 +0800
commit9cfd3a1241864345771be247c531a17de9694610 (patch)
treee8011302bc6d485c1dd77d87763e28342f8339cf /ShellPkg/Library/UefiShellLib
parent1cfe36af68ecc5b3ba4b6ffb253904773dbe7b0c (diff)
downloadedk2-platforms-9cfd3a1241864345771be247c531a17de9694610.tar.xz
ShellPkg: Fix ASCII and UNICODE file pipes.
Fix various errors when piping a UNICODE or ASCII file to a simple shell application that reads standard input and writes it to standard output. 1) When the memory file is created by CreateFileInferfaceMem() to capture the pipe output, no UNICODE BOM is written to the memory file. Later, when the memory file is read by the application using ShellFileHandleReadLine(), the function indicates that the file is ASCII because there is no BOM. 2) If the file is piped as ASCII, the ASCII memory image is not correctly created by FileInterfaceMemWrite() as each ASCII character is followed by '\0' in the image (when the ASCII data is written to the memory image, the file position should only be incremented by half the buffer size). 3) ShellFileHandleReadLine() does not read ASCII files correctly (writes to Buffer need to be cast as CHAR8*). 4) FileInterfaceMemRead() and FileInterfaceMemWrite() as somewhat hard to read and difficult to debug with certain tools due to the typecasting of This. Added a local variable (MemFile) of the correct type to these functions and used it instead of This. Enhancement: ShellFileHandleReadLine() now returns EFI_END_OF_FILE when appropriate. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jim Dailey <jim_dailey@dell.com> reviewed-by: Jaben Carsey <jaben.carsey@intel.com> (cherry picked from commit d2a0d2e6acea4d6a3dbe31b68a9a7fe7511cb478)
Diffstat (limited to 'ShellPkg/Library/UefiShellLib')
-rw-r--r--ShellPkg/Library/UefiShellLib/UefiShellLib.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
index abff0d3114..dac0524fcb 100644
--- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
+++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
@@ -4176,27 +4176,43 @@ ShellFileHandleReadLine(
//
// if we have space save it...
//
- if ((CountSoFar+1)*sizeof(CHAR16) < *Size){
+ if ((CountSoFar + 1) * CharSize < *Size){
ASSERT(Buffer != NULL);
- ((CHAR16*)Buffer)[CountSoFar] = CharBuffer;
- ((CHAR16*)Buffer)[CountSoFar+1] = CHAR_NULL;
+ if (*Ascii) {
+ ((CHAR8*)Buffer)[CountSoFar] = (CHAR8) CharBuffer;
+ ((CHAR8*)Buffer)[CountSoFar+1] = '\0';
+ }
+ else {
+ ((CHAR16*)Buffer)[CountSoFar] = CharBuffer;
+ ((CHAR16*)Buffer)[CountSoFar+1] = CHAR_NULL;
+ }
}
}
//
// if we ran out of space tell when...
//
- if ((CountSoFar+1)*sizeof(CHAR16) > *Size){
- *Size = (CountSoFar+1)*sizeof(CHAR16);
- if (!Truncate) {
- gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);
- } else {
- DEBUG((DEBUG_WARN, "The line was truncated in ShellFileHandleReadLine"));
+ if (Status != EFI_END_OF_FILE){
+ if ((CountSoFar + 1) * CharSize > *Size){
+ *Size = (CountSoFar + 1) * CharSize;
+ if (!Truncate) {
+ gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);
+ } else {
+ DEBUG((DEBUG_WARN, "The line was truncated in ShellFileHandleReadLine"));
+ }
+ return (EFI_BUFFER_TOO_SMALL);
+ }
+
+ if (*Ascii) {
+ if (CountSoFar && ((CHAR8*)Buffer)[CountSoFar - 1] == '\r') {
+ ((CHAR8*)Buffer)[CountSoFar - 1] = '\0';
+ }
+ }
+ else {
+ if (CountSoFar && Buffer[CountSoFar - 1] == L'\r') {
+ Buffer[CountSoFar - 1] = CHAR_NULL;
+ }
}
- return (EFI_BUFFER_TOO_SMALL);
- }
- while(Buffer[StrLen(Buffer)-1] == L'\r') {
- Buffer[StrLen(Buffer)-1] = CHAR_NULL;
}
return (Status);