From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 5F35A21A04811 for ; Thu, 13 Apr 2017 20:40:21 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Apr 2017 20:40:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,197,1488873600"; d="scan'208";a="1135467857" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga001.fm.intel.com with ESMTP; 13 Apr 2017 20:40:20 -0700 Received: from fmsmsx125.amr.corp.intel.com (10.18.125.40) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 13 Apr 2017 20:40:20 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX125.amr.corp.intel.com (10.18.125.40) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 13 Apr 2017 20:40:20 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.246]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.224]) with mapi id 14.03.0319.002; Fri, 14 Apr 2017 11:40:17 +0800 From: "Yao, Jiewen" To: "Wu, Hao A" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH] MdeModulePkg/DxeCore: Add ASSERT to ensure no subtract underflow Thread-Index: AQHSscHv2f1IEcZQF02eTYrjbtO66aHEPhmA Date: Fri, 14 Apr 2017 03:40:15 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503A92C46C@shsmsx102.ccr.corp.intel.com> References: <20170410061557.12688-1-hao.a.wu@intel.com> In-Reply-To: <20170410061557.12688-1-hao.a.wu@intel.com> Accept-Language: zh-CN, 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] MdeModulePkg/DxeCore: Add ASSERT to ensure no subtract underflow 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, 14 Apr 2017 03:40:21 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: jiewen.yao@intel.com > -----Original Message----- > From: Wu, Hao A > Sent: Monday, April 10, 2017 2:16 PM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A ; Yao, Jiewen > Subject: [PATCH] MdeModulePkg/DxeCore: Add ASSERT to ensure no subtract > underflow >=20 > For function SplitRecord() in file PropertiesTable.c, there is a > potential subtract underflow case for line: >=20 > return TotalNewRecordCount - 1; >=20 > However, such case will not happen since the logic in function > SplitTable() ensure that when calling SplitRecord(), the variable > 'TotalNewRecordCount' will not be zero when performing the subtraction. > It will be handled in the previous if statement: >=20 > if (MaxSplitRecordCount =3D=3D 0) { > CopyMem (NewRecord, OldRecord, DescriptorSize); > return 0; > } >=20 > Cc: Jiewen Yao > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Hao Wu > --- > MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c | 5 +++++ > 1 file changed, 5 insertions(+) >=20 > diff --git a/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c > b/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c > index e7c4a95712..6cf5edcbe5 100644 > --- a/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c > +++ b/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c > @@ -576,6 +576,11 @@ SplitRecord ( > TempRecord.NumberOfPages =3D EfiSizeToPages (PhysicalEnd - > PhysicalStart); > } while ((ImageRecord !=3D NULL) && (PhysicalStart < PhysicalEnd)); >=20 > + // > + // The logic in function SplitTable() ensures that TotalNewRecordCount= will > not be zero if the > + // code reaches here. > + // > + ASSERT (TotalNewRecordCount !=3D 0); > return TotalNewRecordCount - 1; > } >=20 > -- > 2.12.0.windows.1