From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from g2t2354.austin.hpe.com (g2t2354.austin.hpe.com [15.233.44.27]) (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 B3C9121A6F105 for ; Tue, 6 Jun 2017 15:04:49 -0700 (PDT) Received: from G2W6310.americas.hpqcorp.net (g2w6310.austin.hp.com [16.197.64.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g2t2354.austin.hpe.com (Postfix) with ESMTPS id 54B9A4A for ; Tue, 6 Jun 2017 22:05:55 +0000 (UTC) Received: from G9W8454.americas.hpqcorp.net (2002:10d8:a104::10d8:a104) by G2W6310.americas.hpqcorp.net (2002:10c5:4034::10c5:4034) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Tue, 6 Jun 2017 22:05:55 +0000 Received: from NAM01-BY2-obe.outbound.protection.outlook.com (15.241.52.13) by G9W8454.americas.hpqcorp.net (16.216.161.4) with Microsoft SMTP Server (TLS) id 15.0.1178.4 via Frontend Transport; Tue, 6 Jun 2017 22:05:54 +0000 Received: from CS1PR84MB0024.NAMPRD84.PROD.OUTLOOK.COM (10.162.189.142) by CS1PR84MB0023.NAMPRD84.PROD.OUTLOOK.COM (10.162.189.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1157.12; Tue, 6 Jun 2017 22:05:51 +0000 Received: from CS1PR84MB0024.NAMPRD84.PROD.OUTLOOK.COM ([10.162.189.142]) by CS1PR84MB0024.NAMPRD84.PROD.OUTLOOK.COM ([10.162.189.142]) with mapi id 15.01.1157.012; Tue, 6 Jun 2017 22:05:51 +0000 From: "Shah, Tapan" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" Thread-Topic: [edk2] [PATCH] ShellPkg/parse: Handle Unicode stream from pipe correctly Thread-Index: AQHS3p8OepFk2HTGHEKT+YUECKzqQ6IXhMyAgADf4oA= Date: Tue, 6 Jun 2017 22:05:50 +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: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=hpe.com; x-originating-ip: [15.203.227.5] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; CS1PR84MB0023; 7:c89RSHF4KRjGwNUW/13IxemRiF/MoeZGM9MFbxUCYfe7q4ebGIgKJZNGfD5MOhglT017/C1osvUyonXkAfZI28o6Zq7/+PVBC3iGScw1rk33Acv0209cNkoKEkCHIN+qPff13oPBZnIcCF0komJ1OlCYAoYAsg9yCsBLv72ys83K6oSUxgrJxRIqgotHuDZM06V6YTaQ0WkV/jDyij9PIj6IaimQC7+p6DgNs8W1bPj0NPrgEKTOTvKcyJ7UBQ6iJ6zdPvuHvaO3M5hqGkmo3tgZ+wpinS/WhiOL0gPBfLbxhJV3/bR2M1W5ZHL08f8BbogLjd6TT7YC3CSjh/Pajg== x-ms-traffictypediagnostic: CS1PR84MB0023: x-ms-office365-filtering-correlation-id: ef02caa9-eb78-444e-e2c2-08d4ad2831b9 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254075)(48565401081)(201703131423075)(201703031133081); SRVR:CS1PR84MB0023; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(227479698468861)(162533806227266)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(3002001)(6055026)(6041248)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123560025)(20161123555025)(20161123564025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:CS1PR84MB0023; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:CS1PR84MB0023; x-forefront-prvs: 033054F29A x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(39410400002)(39400400002)(39860400002)(39450400003)(39840400002)(39850400002)(377454003)(13464003)(77096006)(66066001)(86362001)(229853002)(25786009)(6506006)(33656002)(53546009)(478600001)(50986999)(2900100001)(2501003)(966005)(3660700001)(3280700002)(189998001)(54356999)(5660300001)(6116002)(575784001)(2906002)(55016002)(3846002)(76176999)(102836003)(6246003)(122556002)(74316002)(2950100002)(6306002)(14454004)(305945005)(81166006)(7736002)(8936002)(8676002)(7696004)(53936002)(6436002)(9686003)(38730400002)(19627235001); DIR:OUT; SFP:1102; SCL:1; SRVR:CS1PR84MB0023; H:CS1PR84MB0024.NAMPRD84.PROD.OUTLOOK.COM; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jun 2017 22:05:50.9284 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR84MB0023 X-OriginatorOrg: hpe.com 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 22:04:49 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Tapan Shah -----Original Message----- From: Ni, Ruiyu [mailto:ruiyu.ni@intel.com]=20 Sent: Tuesday, June 06, 2017 3:44 AM To: Ni, Ruiyu ; edk2-devel@lists.01.org Cc: Shah, Tapan Subject: RE: [edk2] [PATCH] ShellPkg/parse: Handle Unicode stream from pipe= correctly Including Tapan. Thanks/Ray > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of=20 > 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=20 > pipe correctly >=20 > The original code expects the Unicode stream from pipe doesn't=20 > 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=20 > stream without BOM. Since now the Unicode steam contains BOM, the=20 > 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,=20 > L.P.
> - Copyright (c) 2009 - 2012, Intel Corporation. All rights=20 > reserved.
> + Copyright (c) 2009 - 2017, Intel Corporation. All rights=20 > + reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of=20 > the BSD License > which accompanies this distribution. The full text of the license=20 > may be found at @@ -56,137 +56,6 @@ IsStdInDataAvailable ( } >=20 > /** > - Function to read a single line (up to but not including the \n)=20 > using StdIn data from a SHELL_FILE_HANDLE. > - > - If the position upon start is 0, then the Ascii Boolean will be=20 > 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=20 > 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=20 > 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,=20 > 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 &&=20 > !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