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.115, mailfrom: zhichao.gao@intel.com) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by groups.io with SMTP; Mon, 15 Jul 2019 17:14:58 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jul 2019 17:14:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,494,1557212400"; d="scan'208";a="318832623" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga004.jf.intel.com with ESMTP; 15 Jul 2019 17:14:57 -0700 Received: from fmsmsx124.amr.corp.intel.com (10.18.125.39) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 15 Jul 2019 17:14:57 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx124.amr.corp.intel.com (10.18.125.39) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 15 Jul 2019 17:14:57 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.134]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.109]) with mapi id 14.03.0439.000; Tue, 16 Jul 2019 08:14:55 +0800 From: "Gao, Zhichao" To: "devel@edk2.groups.io" , "jim.dailey@dell.com" CC: "Carsey, Jaben" , "Ni, Ray" , "afish@apple.com" Subject: Re: [edk2-devel] [PATCH] ShellPkg/Type.c: Add value check before (LoopVar - 1) Thread-Topic: [edk2-devel] [PATCH] ShellPkg/Type.c: Add value check before (LoopVar - 1) Thread-Index: AQHVOt9JGoRbHz3K40qmOOUZk+8a4KbLpjQggAC6voA= Date: Tue, 16 Jul 2019 00:14:54 +0000 Message-ID: <3CE959C139B4C44DBEA1810E3AA6F9000B807F8C@SHSMSX101.ccr.corp.intel.com> References: <20190715073007.25732-1-zhichao.gao@intel.com> <20190715073007.25732-2-zhichao.gao@intel.com> <50888903371147858e578ab497b2c66c@ausx13mps335.AMER.DELL.COM> In-Reply-To: <50888903371147858e578ab497b2c66c@ausx13mps335.AMER.DELL.COM> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: zhichao.gao@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable You are right. I missed the USC2 section. I would update that in next versi= on. Thanks, Zhichao > -----Original Message----- > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of > Jim Dailey > Sent: Monday, July 15, 2019 9:09 PM > To: Gao, Zhichao > Cc: Carsey, Jaben ; Ni, Ray ; > afish@apple.com; devel@edk2.groups.io > Subject: Re: [edk2-devel] [PATCH] ShellPkg/Type.c: Add value check befor= e > (LoopVar - 1) >=20 > Zhichao, >=20 > I believe the same problem exists further into the function in the 'else= ' > clause handling UCS2 characters. >=20 > Regards, > Jim >=20 > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Gao, > Zhichao > Sent: Monday, July 15, 2019 2:30 AM > To: devel@edk2.groups.io > Cc: Jaben Carsey; Ray Ni; Andrew Fish > Subject: [edk2-devel] [PATCH] ShellPkg/Type.c: Add value check before > (LoopVar - 1) >=20 >=20 > [EXTERNAL EMAIL] >=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' && L= oopVar > =3D=3D 0)" before it to make sure (LoopVar - 1) would never encounter a > underflow. >=20 > Cc: Jaben Carsey > Cc: Ray Ni > Cc: Andrew Fish > Signed-off-by: Zhichao Gao > --- > ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) >=20 > diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c > b/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c > index 4efc0a8e24..c1f670c713 100644 > --- a/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c > +++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c > @@ -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 di= splaying > - // each new line from left. > + // In case file begin with single line Feed or Line Feed (0= xA) is > + // encountered & Carriage Return (0xD) was not previous cha= racter, > + // print CR and LF. This is because Shell 2.0 requires carr= iage > + // return Swith line feed for displaying each new line from= left. > // > ShellPrintEx (-1, -1, L"\r\n"); > continue; > -- > 2.21.0.windows.1 >=20 >=20 >=20 >=20 > Dell Corporation Limited is registered in England and Wales. Company > Registration Number: 2081369 > Registered address: Dell House, The Boulevard, Cain Road, Bracknell, > Berkshire, RG12 1LF, UK. > Company details for other Dell UK entities can be found on www.dell.co.= uk. >=20 >=20 >=20