From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 3FFC8219392F4 for ; Sun, 9 Apr 2017 23:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1491804961; x=1523340961; h=from:to:cc:subject:date:message-id; bh=ad9JBvU6n1Ji/3wEPiPqLRtjhf4QtaO+9wQ8JSdFjIk=; b=uBnObX78VQGGdcOSiysilyzQBn9U0scMlXkkXnH1S8SVryI4wnkhltB5 LxktRqsw4Z9JS0N0+PXvdgjTja7h+w==; Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Apr 2017 23:16:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,181,1488873600"; d="scan'208";a="86797919" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.13]) by fmsmga005.fm.intel.com with ESMTP; 09 Apr 2017 23:15:59 -0700 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Jiewen Yao Date: Mon, 10 Apr 2017 14:15:57 +0800 Message-Id: <20170410061557.12688-1-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 Subject: [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: Mon, 10 Apr 2017 06:16:01 -0000 For function SplitRecord() in file PropertiesTable.c, there is a potential subtract underflow case for line: return TotalNewRecordCount - 1; 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: if (MaxSplitRecordCount == 0) { CopyMem (NewRecord, OldRecord, DescriptorSize); return 0; } 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(+) 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 = EfiSizeToPages (PhysicalEnd - PhysicalStart); } while ((ImageRecord != NULL) && (PhysicalStart < PhysicalEnd)); + // + // The logic in function SplitTable() ensures that TotalNewRecordCount will not be zero if the + // code reaches here. + // + ASSERT (TotalNewRecordCount != 0); return TotalNewRecordCount - 1; } -- 2.12.0.windows.1