From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 BDE5721AE30D0 for ; Tue, 6 Jun 2017 08:40:46 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP; 06 Jun 2017 08:41:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,306,1493708400"; d="scan'208";a="1157218610" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga001.fm.intel.com with ESMTP; 06 Jun 2017 08:41:53 -0700 Received: from fmsmsx153.amr.corp.intel.com (10.18.125.6) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 6 Jun 2017 08:41:52 -0700 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.37]) by FMSMSX153.amr.corp.intel.com ([169.254.9.56]) with mapi id 14.03.0319.002; Tue, 6 Jun 2017 08:41:52 -0700 From: "Carsey, Jaben" To: "Ni, Ruiyu" , "Ni, Ruiyu" , "edk2-devel@lists.01.org" Thread-Topic: [edk2] [PATCH] ShellPkg/parse: Handle Unicode stream from pipe correctly Thread-Index: AQHS3p8H0TraU/S0gEugbnPMAWVOTKIX+iWA////WcA= Date: Tue, 6 Jun 2017 15:41:52 +0000 Message-ID: References: <20170606082924.305788-1-ruiyu.ni@intel.com> <734D49CCEBEEF84792F5B80ED585239D5B988FCE@SHSMSX104.ccr.corp.intel.com> In-Reply-To: <734D49CCEBEEF84792F5B80ED585239D5B988FCE@SHSMSX104.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMmYxMjViYmQtMmIxNi00OTM1LTk4OTgtMTNkZjI1MDIxNTZkIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IndtbUxrMlVwZGN4Tm9zeDc4SFhHVWtWTXFvbUdJQVZEZTRoY2JFZlprZUE9In0= x-ctpclassification: CTP_IC x-originating-ip: [10.1.200.108] 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 15:40:46 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I like removing the special local version of the function. Reviewed-by: Jaben Carsey > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ni= , > Ruiyu > Sent: Tuesday, June 06, 2017 1:44 AM > To: Ni, Ruiyu ; edk2-devel@lists.01.org > Subject: Re: [edk2] [PATCH] ShellPkg/parse: Handle Unicode stream from > pipe correctly > Importance: High >=20 > Including Tapan. >=20 > Thanks/Ray >=20 > > -----Original Message----- > > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Ruiyu > > 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 > > > > 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. > > > > 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. > > > > 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(-) > > > > 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. > > > > (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 th= e > BSD > > License > > which accompanies this distribution. The full text of the license m= ay be > found > > at > > @@ -56,137 +56,6 @@ IsStdInDataAvailable ( > > } > > > > /** > > - Function to read a single line (up to but not including the \n) usin= g 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 Buf= fer. > > - @param[in] Truncate If the buffer is large enough, this h= as no > effect. > > - If the buffer is is too small and Tru= ncate is TRUE, > > - the line will be truncated. > > - If the buffer is is too small and Tru= ncate is FALSE, > > - then no read will occur. > > - > > - @retval EFI_SUCCESS The operation was successful. The lin= e 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 > line. > > - Size was updated to the minimum space = required. > > -**/ > > -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, &CharBu= ffer); > > - 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.= The > \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, FALS= E); > > - 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, FA= LSE); > > - > > - } > > - 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 ^ charac= ter > (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); > > > > 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 > > > > _______________________________________________ > > edk2-devel mailing list > > edk2-devel@lists.01.org > > https://lists.01.org/mailman/listinfo/edk2-devel > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel