From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@dell.com header.s=smtpout1 header.b=DEL21bYC; spf=pass (domain: dell.com, ip: 148.163.137.20, mailfrom: jim.dailey@dell.com) Received: from mx0b-00154904.pphosted.com (mx0b-00154904.pphosted.com [148.163.137.20]) by groups.io with SMTP; Mon, 15 Jul 2019 06:09:27 -0700 Received: from pps.filterd (m0170394.ppops.net [127.0.0.1]) by mx0b-00154904.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6FD9OQN001377 for ; Mon, 15 Jul 2019 09:09:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : mime-version : content-transfer-encoding; s=smtpout1; bh=To9rGm+7SiveCq/fBusroo1NG0cB9JXb1PTj+fNsQvs=; b=DEL21bYC17bhN7x0m0AklJfIfEjawwSPyplfYd7QVrB3N9KZVP5TsZdOrWZFGabP3jB2 GrbvPz/Hgw4VLfHfg3b6+EZ5P8g56Q4Cljlg6RqYhSmaDQ62OAW4ky34vKYUvXazWFpq YS1cHh497rUyEUWeMdI5bP7nKhBwirtgS8lgIJvwjiXxbzLrSFKL0scntRV6Eoy6cSRY R/dpsmJFVJh3WKqVwRp43ASgc0wc7XQ2cuag0KZeZ9JWXPA+2lBtyrE6tgqf63PA21+i wZEerwW8KeFFhZZY4vHKYO09d/zPQvzAAja0MyLXh6uSuPIiH/+dsUv5Atn3nihnfhlL cg== Received: from mx0a-00154901.pphosted.com (mx0a-00154901.pphosted.com [67.231.149.39]) by mx0b-00154904.pphosted.com with ESMTP id 2tq9v5pm2d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 15 Jul 2019 09:09:26 -0400 Received: from pps.filterd (m0134746.ppops.net [127.0.0.1]) by mx0a-00154901.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6FD4jLx106115 for ; Mon, 15 Jul 2019 09:09:25 -0400 Received: from ausxippc101.us.dell.com (ausxippc101.us.dell.com [143.166.85.207]) by mx0a-00154901.pphosted.com with ESMTP id 2trrb99pmx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 15 Jul 2019 09:09:25 -0400 X-LoopCount0: from 10.166.136.215 X-PREM-Routing: D-Outbound X-IronPort-AV: E=Sophos;i="5.60,346,1549951200"; d="scan'208";a="1272032322" From: "Jim Dailey" To: CC: , , , 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: AQHVOt9J/jnFbvbCpk6R+gqKUk8PBKbLpjQg Date: Mon, 15 Jul 2019 13:09:22 +0000 Message-ID: <50888903371147858e578ab497b2c66c@ausx13mps335.AMER.DELL.COM> 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: msip_labels: MSIP_Label_17cb76b2-10b8-4fe1-93d4-2202842406cd_Enabled=True; MSIP_Label_17cb76b2-10b8-4fe1-93d4-2202842406cd_SiteId=945c199a-83a2-4e80-9f8c-5a91be5752dd; MSIP_Label_17cb76b2-10b8-4fe1-93d4-2202842406cd_Owner=Jim_Dailey@Dell.com; MSIP_Label_17cb76b2-10b8-4fe1-93d4-2202842406cd_SetDate=2019-07-15T13:05:35.9371205Z; MSIP_Label_17cb76b2-10b8-4fe1-93d4-2202842406cd_Name=External Public; MSIP_Label_17cb76b2-10b8-4fe1-93d4-2202842406cd_Application=Microsoft Azure Information Protection; MSIP_Label_17cb76b2-10b8-4fe1-93d4-2202842406cd_Extended_MSFT_Method=Manual; aiplabel=External Public x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.143.18.86] MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-15_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=979 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907150157 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907150159 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Zhichao, I believe the same problem exists further into the function in the 'else' clause handling UCS2 characters. Regards, Jim -----Original Message----- From: devel@edk2.groups.io On Behalf Of Gao, Zhicha= o 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 (Loo= pVar - 1) [EXTERNAL EMAIL]=20 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1964 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. 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(-) 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 b= ecause - // Shell 2.0 requires carriage return with line feed for disp= laying - // each new line from left. + // In case file begin with single line Feed or Line Feed (0xA= ) is + // encountered & Carriage Return (0xD) was not previous chara= cter, + // print CR and LF. This is because Shell 2.0 requires carria= ge + // return Swith line feed for displaying each new line from l= eft. // ShellPrintEx (-1, -1, L"\r\n"); continue; --=20 2.21.0.windows.1 Dell Corporation Limited is registered in England and Wales. Company Regis= tration Number: 2081369 Registered address: Dell House, The Boulevard, Cain Road, Bracknell, Berk= shire, RG12 1LF, UK. Company details for other Dell UK entities can be found on www.dell.co.uk= .