From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: jaben.carsey@intel.com) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by groups.io with SMTP; Tue, 16 Jul 2019 09:58:11 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jul 2019 09:58:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,499,1559545200"; d="scan'208";a="167707256" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga008.fm.intel.com with ESMTP; 16 Jul 2019 09:58:10 -0700 Received: from fmsmsx112.amr.corp.intel.com (10.18.116.6) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 16 Jul 2019 09:58:10 -0700 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.17]) by FMSMSX112.amr.corp.intel.com ([169.254.5.121]) with mapi id 14.03.0439.000; Tue, 16 Jul 2019 09:58:09 -0700 From: "Carsey, Jaben" To: "Gao, Zhichao" , "devel@edk2.groups.io" CC: "Ni, Ray" , Andrew Fish Subject: Re: [PATCH V2] ShellPkg/Type.c: Add value check before (LoopVar - 1) Thread-Topic: [PATCH V2] ShellPkg/Type.c: Add value check before (LoopVar - 1) Thread-Index: AQHVO7aanNKCOExR8UW079o4P1IXk6bNd9jA Date: Tue, 16 Jul 2019 16:58:09 +0000 Message-ID: References: <20190716091223.22032-1-zhichao.gao@intel.com> In-Reply-To: <20190716091223.22032-1-zhichao.gao@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiOGRmNGJjNjItZjE0NC00YzE5LWJjYmMtY2U0N2ZkNDg4ZTkzIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiTkRBWFRWbXhCRDRQVmM0RHJHMkpUakZQNzNReW15dlpsUjZSa0tRcVRiS0RsNlpIXC92UlQ5RFBJTDNsN2ZrdWMifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action x-originating-ip: [10.1.200.107] MIME-Version: 1.0 Return-Path: jaben.carsey@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jaben Carsey Thanks -Jaben > -----Original Message----- > From: Gao, Zhichao > Sent: Tuesday, July 16, 2019 2:12 AM > To: devel@edk2.groups.io > Cc: Carsey, Jaben ; Ni, Ray ; > Andrew Fish > Subject: [PATCH V2] ShellPkg/Type.c: Add value check before (LoopVar - 1) >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1964 >=20 > If the file begin with single line Feed ('\n'), then > "AsciiChar =3D=3D '\n' && ((CHAR8*)Buffer)[LoopVar-1] !=3D '\r'" > would cause a underflow. Add this condition > "(AsciiChar =3D=3D '\n' && LoopVar =3D=3D 0)" before it to make sure > (LoopVar - 1) would never encounter a underflow. >=20 > Same change in Unicode section. >=20 > Cc: Jaben Carsey > Cc: Ray Ni > Cc: Andrew Fish > Signed-off-by: Zhichao Gao > --- > V2: > 1. Update the copyright > 2. Fix the same issue in unicode section > 3. Fix typo >=20 > .../Library/UefiShellLevel3CommandsLib/Type.c | 24 ++++++++++--------- > 1 file changed, 13 insertions(+), 11 deletions(-) >=20 > diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c > b/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c > index 4efc0a8e24..f0aa57af3d 100644 > --- a/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c > +++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c > @@ -2,7 +2,7 @@ > Main file for Type shell level 3 function. >=20 > (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
> - Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved. > + Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved. > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > **/ > @@ -78,12 +78,13 @@ TypeFileByHandle ( > // Allow Line Feed (LF) (0xA) & Carriage Return (CR) (0xD) > // characters to be displayed as is. > // > - if (AsciiChar =3D=3D '\n' && ((CHAR8*)Buffer)[LoopVar-1] !=3D = '\r') { > + if ((AsciiChar =3D=3D '\n' && LoopVar =3D=3D 0) || > + (AsciiChar =3D=3D '\n' && ((CHAR8*)Buffer)[LoopVar-1] !=3D= '\r')) { > // > - // In case Line Feed (0xA) is encountered & Carriage Return = (0xD) > - // was not the previous character, print CR and LF. This is = because > - // Shell 2.0 requires carriage return with line feed for dis= playing > - // each new line from left. > + // In case file begin with single line Feed or Line Feed (0x= A) is > + // encountered & Carriage Return (0xD) was not previous char= acter, > + // print CR and LF. This is because Shell 2.0 requires carri= age > + // return with line feed for displaying each new line from l= eft. > // > ShellPrintEx (-1, -1, L"\r\n"); > continue; > @@ -121,12 +122,13 @@ TypeFileByHandle ( > // Allow Line Feed (LF) (0xA) & Carriage Return (CR) (0xD) > // characters to be displayed as is. > // > - if (Ucs2Char =3D=3D '\n' && ((CHAR16*)Buffer)[LoopVar-1] !=3D = '\r') { > + if ((Ucs2Char =3D=3D '\n' && LoopVar =3D=3D 0) || > + (Ucs2Char =3D=3D '\n' && ((CHAR16*)Buffer)[LoopVar-1] !=3D= '\r')) { > // > - // In case Line Feed (0xA) is encountered & Carriage Return = (0xD) > - // was not the previous character, print CR and LF. This is = because > - // Shell 2.0 requires carriage return with line feed for dis= playing > - // each new line from left. > + // In case file begin with single line Feed or Line Feed (0x= A) is > + // encountered & Carriage Return (0xD) was not previous char= acter, > + // print CR and LF. This is because Shell 2.0 requires carri= age > + // return with line feed for displaying each new line from l= eft. > // > ShellPrintEx (-1, -1, L"\r\n"); > continue; > -- > 2.21.0.windows.1