From nobody Thu Apr 18 03:38:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1533786269001868.5505712001518; Wed, 8 Aug 2018 20:44:29 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D74CF210E38B3; Wed, 8 Aug 2018 20:44:27 -0700 (PDT) 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 D1F2821959CB2 for ; Wed, 8 Aug 2018 20:44:26 -0700 (PDT) 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:27 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.4]) by orsmga001.jf.intel.com with ESMTP; 08 Aug 2018 20:44:25 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; 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 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,213,1531810800"; d="scan'208";a="80168739" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Thu, 9 Aug 2018 11:45:01 +0800 Message-Id: <20180809034502.131768-2-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: [edk2] [PATCH 1/2] ShellPkg/redirection: Insert \xFEFF after converting ASCII to Unicode 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: , Cc: Jaben Carsey MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RDMRC_1 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When " Cc: Jaben Carsey Reviewed-by: Jaben Carsey --- ShellPkg/Application/Shell/FileHandleWrappers.c | 46 +++++++++++++++++----= ---- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c b/ShellPkg/App= lication/Shell/FileHandleWrappers.c index 8c62eb5862..655854b25d 100644 --- a/ShellPkg/Application/Shell/FileHandleWrappers.c +++ b/ShellPkg/Application/Shell/FileHandleWrappers.c @@ -1924,42 +1924,58 @@ FileInterfaceFileRead( OUT VOID *Buffer ) { + EFI_STATUS Status; + UINT64 Position; CHAR8 *AsciiStrBuffer; CHAR16 *UscStrBuffer; UINTN Size; - UINTN CharNum; - EFI_STATUS Status; if (((EFI_FILE_PROTOCOL_FILE*)This)->Unicode) { // // Unicode + // There might be different file tag for the Unicode file. We cannot u= nconditionally insert the \xFEFF. + // So we choose to leave the file content as is. // return (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Read(((EFI_FILE_PROTOCO= L_FILE*)This)->Orig, BufferSize, Buffer)); } else { // // Ascii // - Size =3D (*BufferSize) / sizeof(CHAR16); - AsciiStrBuffer =3D AllocateZeroPool(Size + sizeof(CHAR8)); + *BufferSize =3D *BufferSize / sizeof (CHAR16) * sizeof (CHAR16); + if (*BufferSize =3D=3D 0) { + return EFI_SUCCESS; + } + Status =3D ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->GetPosition (((EFI_F= ILE_PROTOCOL_FILE*)This)->Orig, &Position); + if (EFI_ERROR (Status)) { + return Status; + } + if (Position =3D=3D 0) { + // + // First two bytes in Buffer is for the Unicode file tag. + // + *(CHAR16 *)Buffer =3D gUnicodeFileTag; + Buffer =3D (CHAR16 *)Buffer + 1; + Size =3D *BufferSize / sizeof (CHAR16) - 1; + } else { + Size =3D *BufferSize / sizeof (CHAR16); + } + AsciiStrBuffer =3D AllocateZeroPool (Size + 1); if (AsciiStrBuffer =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } - UscStrBuffer =3D AllocateZeroPool(*BufferSize + sizeof(CHAR16)); + UscStrBuffer =3D AllocateZeroPool ((Size + 1) * sizeof(CHAR16)); if (UscStrBuffer=3D=3D NULL) { SHELL_FREE_NON_NULL(AsciiStrBuffer); return EFI_OUT_OF_RESOURCES; } - Status =3D (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Read(((EFI_FILE_PRO= TOCOL_FILE*)This)->Orig, &Size, AsciiStrBuffer)); + Status =3D ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Read (((EFI_FILE_PRO= TOCOL_FILE*)This)->Orig, &Size, AsciiStrBuffer); if (!EFI_ERROR(Status)) { - CharNum =3D UnicodeSPrint(UscStrBuffer, *BufferSize + sizeof(CHAR16)= , L"%a", AsciiStrBuffer); - if (CharNum =3D=3D Size) { - CopyMem (Buffer, UscStrBuffer, *BufferSize); - } else { - Status =3D EFI_UNSUPPORTED; - } + AsciiStrToUnicodeStrS (AsciiStrBuffer, UscStrBuffer, Size + 1); + *BufferSize =3D Size * sizeof (CHAR16); + CopyMem (Buffer, UscStrBuffer, *BufferSize); } - SHELL_FREE_NON_NULL(AsciiStrBuffer); - SHELL_FREE_NON_NULL(UscStrBuffer); - return (Status); + SHELL_FREE_NON_NULL (AsciiStrBuffer); + SHELL_FREE_NON_NULL (UscStrBuffer); + return Status; } } =20 --=20 2.16.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu Apr 18 03:38:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1533786271534534.8528191450134; Wed, 8 Aug 2018 20:44:31 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0BDB8210E38B7; Wed, 8 Aug 2018 20:44:29 -0700 (PDT) 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) 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 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 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; 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 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,213,1531810800"; d="scan'208";a="80168745" From: Ruiyu Ni To: edk2-devel@lists.01.org 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: [edk2] [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: , Cc: Jaben Carsey MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RDMRC_1 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1080 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 Reviewed-by: 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/App= lication/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 =3D *BufferSize / sizeof (CHAR16) * sizeof (CHAR16); + if (*BufferSize !=3D 0) { + // + // Make sure the first unicode character is \xFEFF + // + *(CHAR16 *)Buffer =3D gUnicodeFileTag; + Buffer =3D (CHAR16 *)Buffer + 1; + *BufferSize -=3D sizeof (gUnicodeFileTag); + } + + Status =3D SHELL_GET_ENVIRONMENT_VARIABLE ( + ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, + BufferSize, + Buffer + ); + if (!EFI_ERROR (Status) || (Status =3D=3D EFI_BUFFER_TOO_SMALL)) { + // + // BufferSize is valid and needs update when Status is Success or Buff= erTooSmall. + // + *BufferSize +=3D sizeof (gUnicodeFileTag); + } + return Status; } =20 /** --=20 2.16.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel