From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0BCEC21E0C304 for ; Fri, 28 Jul 2017 02:10:39 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP; 28 Jul 2017 02:12:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,424,1496127600"; d="scan'208";a="112925118" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga004.jf.intel.com with ESMTP; 28 Jul 2017 02:12:43 -0700 Received: from fmsmsx155.amr.corp.intel.com (10.18.116.71) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 28 Jul 2017 02:12:42 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX155.amr.corp.intel.com (10.18.116.71) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 28 Jul 2017 02:12:42 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.146]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.94]) with mapi id 14.03.0319.002; Fri, 28 Jul 2017 17:12:38 +0800 From: "Shi, Steven" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH] ShellPkg: Avoid buffer out-of-bound access Thread-Index: AQHTBehiZHGL2Cdh9UGNwPvkQwU+BqJo9zcQ Date: Fri, 28 Jul 2017 09:12:38 +0000 Message-ID: <06C8AB66E78EE34A949939824ABE2B313B54C715@shsmsx102.ccr.corp.intel.com> References: <20170726082227.33224-1-ruiyu.ni@intel.com> In-Reply-To: <20170726082227.33224-1-ruiyu.ni@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] ShellPkg: Avoid buffer out-of-bound access X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jul 2017 09:10:39 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Steven Shi Thanks Steven Shi > -----Original Message----- > From: Ni, Ruiyu > Sent: Wednesday, July 26, 2017 4:22 PM > To: edk2-devel@lists.01.org > Cc: Shi, Steven > Subject: [PATCH] ShellPkg: Avoid buffer out-of-bound access >=20 > PathSize is the number of bytes in PathForReturn buffer so > PathForReturn[PathSize - 1] incorrectly accesses the last > character in the buffer, > PathForReturn[PathSize / sizeof (CHAR16) - 1] should be used. >=20 > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Ruiyu Ni > Cc: Steven Shi > --- > ShellPkg/Application/Shell/ShellProtocol.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/ShellPkg/Application/Shell/ShellProtocol.c > b/ShellPkg/Application/Shell/ShellProtocol.c > index b3b8acc0d0..991fb58ca7 100644 > --- a/ShellPkg/Application/Shell/ShellProtocol.c > +++ b/ShellPkg/Application/Shell/ShellProtocol.c > @@ -477,7 +477,7 @@ EfiShellGetFilePathFromDevicePath( > // UEFI Shell spec section 3.7) > if ((PathSize !=3D 0) && > (PathForReturn !=3D NULL) && > - (PathForReturn[PathSize - 1] !=3D L'\\') && > + (PathForReturn[PathSize / sizeof (CHAR16) - 1] !=3D L'\\') &= & > (AlignedNode->PathName[0] !=3D L'\\')) { > PathForReturn =3D StrnCatGrow (&PathForReturn, &PathSize, L"\\= ", 1); > } > -- > 2.12.2.windows.2