From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: jaben.carsey@intel.com) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by groups.io with SMTP; Mon, 15 Jul 2019 07:30:59 -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 orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jul 2019 07:30:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,493,1557212400"; d="scan'208";a="318693261" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga004.jf.intel.com with ESMTP; 15 Jul 2019 07:30:58 -0700 Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 15 Jul 2019 07:30:58 -0700 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.17]) by fmsmsx116.amr.corp.intel.com ([169.254.2.161]) with mapi id 14.03.0439.000; Mon, 15 Jul 2019 07:30:57 -0700 From: "Carsey, Jaben" To: "Gao, Zhichao" , "devel@edk2.groups.io" CC: "Ni, Ray" , Andrew Fish Subject: Re: [PATCH] ShellPkg/Type.c: Add value check before (LoopVar - 1) Thread-Topic: [PATCH] ShellPkg/Type.c: Add value check before (LoopVar - 1) Thread-Index: AQHVOt9Fc4hU0vIPuUuC4bcADVqr6qbLvbhA Date: Mon, 15 Jul 2019 14:30:57 +0000 Message-ID: References: <20190715073007.25732-1-zhichao.gao@intel.com> <20190715073007.25732-2-zhichao.gao@intel.com> In-Reply-To: <20190715073007.25732-2-zhichao.gao@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZGRlZDczZjQtY2FmNi00ZWUwLTk5NjAtNDU5MDY0YjVlNTVjIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiTFZIY09UQ2Nva3phczdldEc0XC9aak9aMGxxM0N2bnFZZVVGQkZXQlduRVQ3UXlPeWplUENRTVwvbzcxamozMTRtIn0= 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 Please remove the typo (there is an extra S after 'return'). This line: // return Swith line feed for displaying each new line from left. > -----Original Message----- > From: Gao, Zhichao > Sent: Monday, July 15, 2019 12:30 AM > To: devel@edk2.groups.io > Cc: Carsey, Jaben ; Ni, Ray ; > Andrew Fish > Subject: [PATCH] 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 > 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 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 Swith line feed for displaying each new line from = left. > // > ShellPrintEx (-1, -1, L"\r\n"); > continue; > -- > 2.21.0.windows.1