diff options
author | Ruiyu Ni <ruiyu.ni@intel.com> | 2018-08-09 11:43:24 +0800 |
---|---|---|
committer | Ruiyu Ni <ruiyu.ni@intel.com> | 2018-08-16 16:03:16 +0800 |
commit | 52047be0243074f50fab45650f36ae693c93d1b3 (patch) | |
tree | 9c76f0cfb1c0d9dfff8ee3634e3c504c6522f889 /ShellPkg/Application/Shell | |
parent | bc0d3e29122df5fe4b71f6ef62e8652ea29fd6a0 (diff) | |
download | edk2-52047be0243074f50fab45650f36ae693c93d1b3.zip edk2-52047be0243074f50fab45650f36ae693c93d1b3.tar.gz edk2-52047be0243074f50fab45650f36ae693c93d1b3.tar.bz2 |
ShellPkg/redirection: Insert \xFEFF for ENV variable redirection
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1080
Per Shell spec 2.2 chapter 3.4.4.2, Unicode file tag should be
inserted in the output from the input redirected variable, to ensure
it looks like a UCS-2 encode file.
The patch fixes this issue.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Diffstat (limited to 'ShellPkg/Application/Shell')
-rw-r--r-- | ShellPkg/Application/Shell/FileHandleWrappers.c | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c b/ShellPkg/Application/Shell/FileHandleWrappers.c index 655854b..bcce055 100644 --- a/ShellPkg/Application/Shell/FileHandleWrappers.c +++ b/ShellPkg/Application/Shell/FileHandleWrappers.c @@ -1148,15 +1148,35 @@ FileInterfaceEnvDelete( EFI_STATUS
EFIAPI
FileInterfaceEnvRead(
- IN EFI_FILE_PROTOCOL *This,
- IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ IN EFI_FILE_PROTOCOL *This,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
)
{
- return (SHELL_GET_ENVIRONMENT_VARIABLE(
- ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,
- BufferSize,
- Buffer));
+ EFI_STATUS Status;
+
+ *BufferSize = *BufferSize / sizeof (CHAR16) * sizeof (CHAR16);
+ if (*BufferSize != 0) {
+ //
+ // Make sure the first unicode character is \xFEFF
+ //
+ *(CHAR16 *)Buffer = gUnicodeFileTag;
+ Buffer = (CHAR16 *)Buffer + 1;
+ *BufferSize -= sizeof (gUnicodeFileTag);
+ }
+
+ Status = SHELL_GET_ENVIRONMENT_VARIABLE (
+ ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,
+ BufferSize,
+ Buffer
+ );
+ if (!EFI_ERROR (Status) || (Status == EFI_BUFFER_TOO_SMALL)) {
+ //
+ // BufferSize is valid and needs update when Status is Success or BufferTooSmall.
+ //
+ *BufferSize += sizeof (gUnicodeFileTag);
+ }
+ return Status;
}
/**
|