From nobody Sat Apr 27 13:14:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43773+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43773+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1563268348; cv=none; d=zoho.com; s=zohoarc; b=jb3PQ9x7Bf2Gykn1f0fkkF6kTw6hUO77hrMTJnoczI1NuukeETSTH+BBZ43yu2l8JmD7vJjayUVks1+uIlielqPNofJHU/vRPjN9/ysfLuKbFyjvn/h1jXD48bQsnkGPlSga3b9enL8gK5DlZxuHDyY97diS4UI/cvqIwI5wqKI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563268348; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=FuGdGAmvZ35SIaYnM9W3OI7JlpyiWf8yZ57RKe8vOdQ=; b=bbjkPkARcd9GPOK5hWcMeFb9ei5zDjc7MXwEMp8nUfXdpJVkmJ0Mzeecy1GBhZVQRxMYIk2Z8CdwqVuRHT+hL01t1AcOR5O9IOzsh4yQwNEFKXE7empQg/McjEpok1Y/5F1hm2TTHIiJBoJHmPiKG0NMd48yC0PbFcnVkjkY3FI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43773+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1563268348583262.50525134246084; Tue, 16 Jul 2019 02:12:28 -0700 (PDT) Return-Path: X-Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by groups.io with SMTP; Tue, 16 Jul 2019 02:12:27 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jul 2019 02:12:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,497,1557212400"; d="scan'208";a="187302050" X-Received: from fieedk001.ccr.corp.intel.com ([10.239.33.119]) by fmsmga001.fm.intel.com with ESMTP; 16 Jul 2019 02:12:25 -0700 From: "Gao, Zhichao" To: devel@edk2.groups.io Cc: Jaben Carsey , Ray Ni , Andrew Fish Subject: [edk2-devel] [PATCH V2] ShellPkg/Type.c: Add value check before (LoopVar - 1) Date: Tue, 16 Jul 2019 17:12:23 +0800 Message-Id: <20190716091223.22032-1-zhichao.gao@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,zhichao.gao@intel.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1563268348; bh=Eu3ujLdhiSjhZJzAiwQjPyujwE4X5a3ob88X6k9tMCU=; h=Cc:Date:From:Reply-To:Subject:To; b=J+udQKKaeeixXW2Uxtry7VVPbplEnHLSqNfY6+HHnmU4/Itd6rdP6c7vcEcPDLqqWhB 5p5iiFHaCgrWlWmUeTi8XSCHny6nlD6Boyw63jMNzpQexnCN/Al0By4LCcSGBGULyekqJ XFz3fIqdsJz01PWMRYzzDQ2gy12fr3cEC5k= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" 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. Same change in Unicode section. Cc: Jaben Carsey Cc: Ray Ni Cc: Andrew Fish Signed-off-by: Zhichao Gao Reviewed-by: Andrew Fish Reviewed-by: Jaben Carsey --- V2: 1. Update the copyright 2. Fix the same issue in unicode section 3. Fix typo .../Library/UefiShellLevel3CommandsLib/Type.c | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) 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 (0= xD) - // was not the previous character, print CR and LF. This is be= cause - // Shell 2.0 requires carriage return with line feed for displ= aying - // 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 charac= ter, + // print CR and LF. This is because Shell 2.0 requires carriage + // return with line feed for displaying each new line from lef= t. // 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 (0= xD) - // was not the previous character, print CR and LF. This is be= cause - // Shell 2.0 requires carriage return with line feed for displ= aying - // 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 charac= ter, + // print CR and LF. This is because Shell 2.0 requires carriage + // return with line feed for displaying each new line from lef= t. // ShellPrintEx (-1, -1, L"\r\n"); continue; --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#43773): https://edk2.groups.io/g/devel/message/43773 Mute This Topic: https://groups.io/mt/32488137/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-