From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D0D12210E38B1 for ; Wed, 8 Aug 2018 20:44:27 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Aug 2018 20:44:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,213,1531810800"; d="scan'208";a="80168745" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.4]) by orsmga001.jf.intel.com with ESMTP; 08 Aug 2018 20:44:26 -0700 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Jaben Carsey Date: Thu, 9 Aug 2018 11:45:02 +0800 Message-Id: <20180809034502.131768-3-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.16.1.windows.1 In-Reply-To: <20180809034502.131768-1-ruiyu.ni@intel.com> References: <20180809034502.131768-1-ruiyu.ni@intel.com> Subject: [PATCH 2/2] ShellPkg/redirection: Insert \xFEFF for ENV variable redirection X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Aug 2018 03:44:28 -0000 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 Cc: Jaben Carsey --- ShellPkg/Application/Shell/FileHandleWrappers.c | 34 ++++++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c b/ShellPkg/Application/Shell/FileHandleWrappers.c index 655854b25d..bcce055321 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; } /** -- 2.16.1.windows.1