]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/DxeCore: Add ASSERT to ensure no subtract underflow
authorHao Wu <hao.a.wu@intel.com>
Wed, 22 Mar 2017 02:08:55 +0000 (10:08 +0800)
committerHao Wu <hao.a.wu@intel.com>
Fri, 14 Apr 2017 05:13:51 +0000 (13:13 +0800)
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;
  }

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c

index e7c4a9571250dd264e808d8b86ad1d38cabb1cb4..6cf5edcbe5d94f17c764095ee128aea35f1589a8 100644 (file)
@@ -576,6 +576,11 @@ SplitRecord (
     TempRecord.NumberOfPages = EfiSizeToPages (PhysicalEnd - PhysicalStart);\r
   } while ((ImageRecord != NULL) && (PhysicalStart < PhysicalEnd));\r
 \r
+  //\r
+  // The logic in function SplitTable() ensures that TotalNewRecordCount will not be zero if the\r
+  // code reaches here.\r
+  //\r
+  ASSERT (TotalNewRecordCount != 0);\r
   return TotalNewRecordCount - 1;\r
 }\r
 \r