From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 CCE7321AE30D2 for ; Tue, 6 Jun 2017 01:42:48 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jun 2017 01:43:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,305,1493708400"; d="scan'208";a="110909381" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga005.fm.intel.com with ESMTP; 06 Jun 2017 01:43:54 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 6 Jun 2017 01:43:54 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.151]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.116]) with mapi id 14.03.0319.002; Tue, 6 Jun 2017 16:43:53 +0800 From: "Ni, Ruiyu" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" Thread-Topic: [edk2] [PATCH] ShellPkg/parse: Handle Unicode stream from pipe correctly Thread-Index: AQHS3p8Qj0EC+1rIXUG6B6VeZX4gkaIXhMNg Date: Tue, 6 Jun 2017 08:43:51 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5B988FCE@SHSMSX104.ccr.corp.intel.com> References: <20170606082924.305788-1-ruiyu.ni@intel.com> In-Reply-To: <20170606082924.305788-1-ruiyu.ni@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] ShellPkg/parse: Handle Unicode stream from pipe correctly X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Jun 2017 08:42:49 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Including Tapan. Thanks/Ray > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ru= iyu > Ni > Sent: Tuesday, June 6, 2017 4:29 PM > To: edk2-devel@lists.01.org > Subject: [edk2] [PATCH] ShellPkg/parse: Handle Unicode stream from pipe > correctly >=20 > The original code expects the Unicode stream from pipe doesn't > contains the Unicode BOM. > But that's not true. > Commit [9ed21946c76e430097e9c4e59b419af928e0cb8c] changes > CreateFileInterfaceMem() to add the BOM for Unicode stream. >=20 > When parse pipe support was firstly added, a private implementation > ParseReturnStdInLine() was created to specially handle > the Unicode stream without BOM. Since now the Unicode steam contains > BOM, the private implementation can be removed and > ShellFileHandleReturnLine() can be used directly. >=20 > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Ruiyu Ni > Cc: Tapan Shah > --- > .../Library/UefiShellLevel2CommandsLib/Parse.c | 145 +--------------= ------ > 1 file changed, 3 insertions(+), 142 deletions(-) >=20 > diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Parse.c > b/ShellPkg/Library/UefiShellLevel2CommandsLib/Parse.c > index 4b1973a505..85c39ba78f 100644 > --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Parse.c > +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Parse.c > @@ -2,7 +2,7 @@ > Main file for Parse shell level 2 function. >=20 > (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
> - Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.
> + Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be found > at > @@ -56,137 +56,6 @@ IsStdInDataAvailable ( > } >=20 > /** > - Function to read a single line (up to but not including the \n) using = StdIn data > from a SHELL_FILE_HANDLE. > - > - If the position upon start is 0, then the Ascii Boolean will be set. = This should be > - maintained and not changed for all operations with the same file. > - > - @param[in] Handle SHELL_FILE_HANDLE to read from. > - @param[in, out] Buffer The pointer to buffer to read into. > - @param[in, out] Size The pointer to number of bytes in Buffe= r. > - @param[in] Truncate If the buffer is large enough, this has= no effect. > - If the buffer is is too small and Trunc= ate is TRUE, > - the line will be truncated. > - If the buffer is is too small and Trunc= ate is FALSE, > - then no read will occur. > - > - @retval EFI_SUCCESS The operation was successful. The line = is stored in > - Buffer. > - @retval EFI_INVALID_PARAMETER Handle was NULL. > - @retval EFI_INVALID_PARAMETER Size was NULL. > - @retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the l= ine. > - Size was updated to the minimum space re= quired. > -**/ > -EFI_STATUS > -ShellFileHandleReadStdInLine( > - IN SHELL_FILE_HANDLE Handle, > - IN OUT CHAR16 *Buffer, > - IN OUT UINTN *Size, > - IN BOOLEAN Truncate > - ) > -{ > - EFI_STATUS Status; > - CHAR16 CharBuffer; > - UINTN CharSize; > - UINTN CountSoFar; > - UINT64 OriginalFilePosition; > - > - > - if (Handle =3D=3D NULL > - ||Size =3D=3D NULL > - ){ > - return (EFI_INVALID_PARAMETER); > - } > - if (Buffer =3D=3D NULL) { > - ASSERT(*Size =3D=3D 0); > - } else { > - *Buffer =3D CHAR_NULL; > - } > - gEfiShellProtocol->GetFilePosition (Handle, &OriginalFilePosition); > - > - for (CountSoFar =3D 0;;CountSoFar++){ > - CharBuffer =3D 0; > - CharSize =3D sizeof(CHAR16); > - Status =3D gEfiShellProtocol->ReadFile (Handle, &CharSize, &CharBuff= er); > - if ( EFI_ERROR(Status) > - || CharSize =3D=3D 0 > - || (CharBuffer =3D=3D L'\n') > - ){ > - break; > - } > - // > - // if we have space save it... > - // > - if ((CountSoFar+1)*sizeof(CHAR16) < *Size){ > - ASSERT(Buffer !=3D NULL); > - ((CHAR16*)Buffer)[CountSoFar] =3D CharBuffer; > - ((CHAR16*)Buffer)[CountSoFar+1] =3D CHAR_NULL; > - } > - } > - > - // > - // if we ran out of space tell when... > - // > - if ((CountSoFar+1)*sizeof(CHAR16) > *Size){ > - *Size =3D (CountSoFar+1)*sizeof(CHAR16); > - if (!Truncate) { > - gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition); > - } else { > - DEBUG((DEBUG_WARN, "The line was truncated in > ShellFileHandleReadLine")); > - } > - return (EFI_BUFFER_TOO_SMALL); > - } > - while(Buffer[StrLen(Buffer)-1] =3D=3D L'\r') { > - Buffer[StrLen(Buffer)-1] =3D CHAR_NULL; > - } > - > - return (Status); > -} > - > - > -/** > - Function to read a single line using StdIn from a SHELL_FILE_HANDLE. T= he \n is > not included in the returned > - buffer. The returned buffer must be callee freed. > - > - If the position upon start is 0, then the Ascii Boolean will be set. = This should be > - maintained and not changed for all operations with the same file. > - > - @param[in] Handle SHELL_FILE_HANDLE to read from. > - > - @return The line of text from the file. > - @retval NULL There was not enough memory available. > - > - @sa ShellFileHandleReadLine > -**/ > -CHAR16* > -ParseReturnStdInLine ( > - IN SHELL_FILE_HANDLE Handle > - ) > -{ > - CHAR16 *RetVal; > - UINTN Size; > - EFI_STATUS Status; > - > - Size =3D 0; > - RetVal =3D NULL; > - > - Status =3D ShellFileHandleReadStdInLine (Handle, RetVal, &Size, FALSE)= ; > - if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { > - RetVal =3D AllocateZeroPool(Size); > - if (RetVal =3D=3D NULL) { > - return (NULL); > - } > - Status =3D ShellFileHandleReadStdInLine (Handle, RetVal, &Size, FALS= E); > - > - } > - if (EFI_ERROR(Status) && (RetVal !=3D NULL)) { > - FreePool(RetVal); > - RetVal =3D NULL; > - } > - return (RetVal); > -} > - > -/** > Handle stings for SFO Output with escape character ^ in a string > 1. Quotation marks in the string must be escaped by using a ^ characte= r (i.e. > ^"). > 2. The ^ character may be inserted using ^^. > @@ -281,11 +150,7 @@ PerformParsing( > ShellStatus =3D SHELL_NOT_FOUND; > } else { > for (LoopVariable =3D 0 ; LoopVariable < ShellCommandInstance > && !ShellFileHandleEof(FileHandle);) { > - if (StreamingUnicode) { > - TempLine =3D ParseReturnStdInLine (FileHandle); > - } else { > - TempLine =3D ShellFileHandleReturnLine (FileHandle, &Ascii); > - } > + TempLine =3D ShellFileHandleReturnLine (FileHandle, &Ascii); >=20 > if ((TempLine =3D=3D NULL) || (*TempLine =3D=3D CHAR_NULL && > StreamingUnicode)) { > break; > @@ -304,11 +169,7 @@ PerformParsing( > if (LoopVariable =3D=3D ShellCommandInstance) { > LoopVariable =3D 0; > while(1) { > - if (StreamingUnicode) { > - TempLine =3D ParseReturnStdInLine (FileHandle); > - } else { > - TempLine =3D ShellFileHandleReturnLine (FileHandle, &Ascii); > - } > + TempLine =3D ShellFileHandleReturnLine (FileHandle, &Ascii); > if (TempLine =3D=3D NULL > || *TempLine =3D=3D CHAR_NULL > || StrStr (TempLine, L"ShellCommand,") =3D=3D TempLine) { > -- > 2.12.2.windows.2 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel