From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@apple.com header.s=20180706 header.b=G0sen9Ln; spf=pass (domain: apple.com, ip: 17.171.2.72, mailfrom: afish@apple.com) Received: from ma1-aaemail-dr-lapp03.apple.com (ma1-aaemail-dr-lapp03.apple.com [17.171.2.72]) by groups.io with SMTP; Tue, 16 Jul 2019 10:18:32 -0700 Received: from pps.filterd (ma1-aaemail-dr-lapp03.apple.com [127.0.0.1]) by ma1-aaemail-dr-lapp03.apple.com (8.16.0.27/8.16.0.27) with SMTP id x6GHGsJG044320; Tue, 16 Jul 2019 10:18:30 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=sender : from : message-id : content-type : mime-version : subject : date : in-reply-to : cc : to : references; s=20180706; bh=pxNwDeOghHxY6GfZo0ZfB2404FfnI+B0ZHO0Wb++IyE=; b=G0sen9LnSfDS5d+56AQu7ztKvdS8O7aQmJURMCi5cl2XkpoLJmxMTpnuSvM9F/t2R7yO Tz5pYKWeucrHO4QmT7zPJ/5vv/briHg5vKIfxrfv0KzUo20EH55nnCZnV/sCR4VNzli+ VUBnqB+Bkfcg1MqQLQQUHe4J8puYWxsFj7YwEUsurWNzFLTaqrqr9mDefKp6CXd/cwLh 2f0c8DjE0cVX3YNWqrc5qttsLeHvjWKjD4dNzxh1g37Pko6KqjmSPW4nrK0TOCpPmjih nHU92vCVdWiuQoHYhUTMbdbclRebruAFnu38Fr9Gk35UNOoSBbxpYTzbZy5yDRc1qo+r bg== Received: from ma1-mtap-s02.corp.apple.com (ma1-mtap-s02.corp.apple.com [17.40.76.6]) by ma1-aaemail-dr-lapp03.apple.com with ESMTP id 2tqe9xekmk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Tue, 16 Jul 2019 10:18:30 -0700 Received: from nwk-mmpp-sz10.apple.com (nwk-mmpp-sz10.apple.com [17.128.115.122]) by ma1-mtap-s02.corp.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPS id <0PUQ0094GW2TS7B0@ma1-mtap-s02.corp.apple.com>; Tue, 16 Jul 2019 10:18:30 -0700 (PDT) Received: from process_milters-daemon.nwk-mmpp-sz10.apple.com by nwk-mmpp-sz10.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) id <0PUQ00800VP6LL00@nwk-mmpp-sz10.apple.com>; Tue, 16 Jul 2019 10:18:29 -0700 (PDT) X-Va-A: X-Va-T-CD: cc266deaad7eb7ffbfed829103b9a0fb X-Va-E-CD: f221c89e35984794a565f16849b27f4d X-Va-R-CD: df249de9ea893ed490d4afd317fdcde0 X-Va-CD: 0 X-Va-ID: 5aab52d0-34ea-4010-9e77-dd628af1638f X-V-A: X-V-T-CD: cc266deaad7eb7ffbfed829103b9a0fb X-V-E-CD: f221c89e35984794a565f16849b27f4d X-V-R-CD: df249de9ea893ed490d4afd317fdcde0 X-V-CD: 0 X-V-ID: 936bca86-9f1e-4865-82e9-e45110753cb3 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-16_04:,, signatures=0 Received: from [17.235.3.231] (unknown [17.235.3.231]) by nwk-mmpp-sz10.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPSA id <0PUQ00AUMW2QVO00@nwk-mmpp-sz10.apple.com>; Tue, 16 Jul 2019 10:18:28 -0700 (PDT) Sender: afish@apple.com From: "Andrew Fish" Message-id: <2F723E59-FFE9-49A6-855D-073147983C53@apple.com> MIME-version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: [edk2-devel] [PATCH V2] ShellPkg/Type.c: Add value check before (LoopVar - 1) Date: Tue, 16 Jul 2019 10:18:25 -0700 In-reply-to: Cc: "Gao, Zhichao" , "Ni, Ray" To: devel@edk2.groups.io, jaben.carsey@intel.com References: <20190716091223.22032-1-zhichao.gao@intel.com> X-Mailer: Apple Mail (2.3445.104.11) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-16_04:,, signatures=0 Content-type: multipart/alternative; boundary="Apple-Mail=_20842B4E-EFB2-4A5A-88E6-8945CE1D87F0" --Apple-Mail=_20842B4E-EFB2-4A5A-88E6-8945CE1D87F0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Reviewed-by: Andrew Fish Thanks, Andrew Fish > On Jul 16, 2019, at 9:58 AM, Carsey, Jaben wrot= e: >=20 > Reviewed-by: Jaben Carsey > >=20 > Thanks > -Jaben >=20 >> -----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. <= BR> >> + Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved. <= BR> >> 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 Retur= n (0xD) >> - // was not the previous character, print CR and LF. This i= s because >> - // Shell 2.0 requires carriage return with line feed for d= isplaying >> - // 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 ch= aracter, >> + // print CR and LF. This is because Shell 2.0 requires car= riage >> + // return with line feed for displaying each new line from= left. >> // >> 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 Retur= n (0xD) >> - // was not the previous character, print CR and LF. This i= s because >> - // Shell 2.0 requires carriage return with line feed for d= isplaying >> - // 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 ch= aracter, >> + // print CR and LF. This is because Shell 2.0 requires car= riage >> + // return with line feed for displaying each new line from= left. >> // >> ShellPrintEx (-1, -1, L"\r\n"); >> continue; >> -- >> 2.21.0.windows.1 >=20 >=20 >=20 --Apple-Mail=_20842B4E-EFB2-4A5A-88E6-8945CE1D87F0 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Reviewed-by: Andrew Fi= sh <afish@apple.com>= ;

Thanks,

Andrew Fish

On Jul 16, 2019, at 9:58 AM, Carsey, Jaben= <jaben.carsey@inte= l.com> wrote:

Reviewed-by: Jaben Carsey <jaben.carse= y@intel.com>
Thanks
-Jaben

-----Orig= inal Message-----
From: Gao, Zhichao
Sent: Tues= day, July 16, 2019 2:12 AM
To: deve= l@edk2.groups.io
Cc: Carsey, Jaben <jaben.carsey@intel.com>; Ni, Ray = <ray.ni@intel.com>= ;
Andrew Fish <afish@apple.com>
Subject: [PATCH V2] ShellPkg/Type.= c: Add value check before (LoopVar - 1)

REF: <= a href=3D"https://bugzilla.tianocore.org/show_bug.cgi?id=3D1964" class=3D""= >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 s= ure
(LoopVar - 1) would never encounter a underflow.

Same change in Unicode section.

Cc: Jaben Carsey <jaben.carsey@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Andrew Fish <af= ish@apple.com>
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>=
---
V2:
1. Update the copyright<= br class=3D"">2. Fix the same issue in unicode section
3. Fix= typo

.../Library/UefiShellLevel3CommandsLib/T= ype.c | 24 ++++++++++---------
1 file changed, 13 insertions(= +), 11 deletions(-)

diff --git a/ShellPkg/Libr= ary/UefiShellLevel3CommandsLib/Type.c
b/ShellPkg/Library/Uefi= ShellLevel3CommandsLib/Type.c
index 4efc0a8e24..f0aa57af3d 10= 0644
--- a/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c=
+++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c
@@ -2,7 +2,7 @@
  Main file for Type she= ll level 3 function.

  (C) Copyright= 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
-  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved= . <BR>
+  Copyright (c) 2009 - 2019, Intel Corpora= tion. All rights reserved. <BR>
  SPDX-Licens= e-Identifier: BSD-2-Clause-Patent

**/
@@ -78,12 +78,13 @@ TypeFileByHandle (
  &nb= sp;       // Allow Line Feed (LF) (0xA) = & Carriage Return (CR) (0xD)
    &nbs= p;     // characters to be displayed as is.
          //
-          if (Ascii= Char =3D=3D '\n' && ((CHAR8*)Buffer)[LoopVar-1] !=3D '\r') {
+          if ((AsciiC= har =3D=3D '\n' && LoopVar =3D=3D 0) ||
+   = ;           (AsciiCh= ar =3D=3D '\n' && ((CHAR8*)Buffer)[LoopVar-1] !=3D '\r')) {
           &n= bsp;//
-         &nbs= p;  // In case Line Feed (0xA) is encountered & Carriage Retu= rn (0xD)
-         &n= bsp;  // was not the previous character, print CR and LF. This is= because
-         &n= bsp;  // Shell 2.0 requires carriage return with line feed for di= splaying
-         &n= bsp;  // each new line from left.
+   &nb= sp;        // In case file begin wi= th single line Feed or Line Feed (0xA) is
+    = ;        // encountered & Carri= age Return (0xD) was not previous character,
+   &n= bsp;        // print CR and LF. Thi= s is because Shell 2.0 requires carriage
+    =         // return with line feed fo= r displaying each new line from left.
    = ;        //
 &nb= sp;          ShellPrintEx= (-1, -1, L"\r\n");
       = ;     continue;
@@ -121,12 +122,13 @= @ TypeFileByHandle (
      &nbs= p;   // Allow Line Feed (LF) (0xA) & Carriage Return (CR= ) (0xD)
         = ; // characters to be displayed as is.
   = ;       //
-   &= nbsp;      if (Ucs2Char =3D=3D '\n' &&= ; ((CHAR16*)Buffer)[LoopVar-1] !=3D '\r') {
+   &nb= sp;      if ((Ucs2Char =3D=3D '\n' &&= LoopVar =3D=3D 0) ||
+       &= nbsp;      (Ucs2Char =3D=3D '\n' && (= (CHAR16*)Buffer)[LoopVar-1] !=3D '\r')) {
   &= nbsp;        //
- &nb= sp;          // In case L= ine Feed (0xA) is encountered & Carriage Return (0xD)
- &= nbsp;          // was not= the previous character, print CR and LF. This is because
- &= nbsp;          // Shell 2= .0 requires carriage return with line feed for displaying
- &= nbsp;          // each ne= w line from left.
+        = ;    // In case file begin with single line Feed or Lin= e Feed (0xA) is
+        &= nbsp;   // encountered & Carriage Return (0xD) was not p= revious character,
+       &nbs= p;    // print CR and LF. This is because Shell 2.0 req= uires carriage
+        &n= bsp;   // return with line feed for displaying each new line= from left.
        &= nbsp;   //
      = ;      ShellPrintEx (-1, -1, L"\r\n");
           &= nbsp;continue;
--
2.21.0.windows.1



--Apple-Mail=_20842B4E-EFB2-4A5A-88E6-8945CE1D87F0--