Fix range check bugs

This is a patch hunting for fuzzing failures and adding
appropriate range checks.


Change-Id: Ieae02b7e461b9a6c5e25de6c663a768f7a0d5e10
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/sections/cper-section-dmar-iommu.c b/sections/cper-section-dmar-iommu.c
index 99af77c..c411cf2 100644
--- a/sections/cper-section-dmar-iommu.c
+++ b/sections/cper-section-dmar-iommu.c
@@ -13,8 +13,12 @@
 #include <libcper/sections/cper-section-dmar-iommu.h>
 
 //Converts a single IOMMU specific DMAr CPER section into JSON IR.
-json_object *cper_section_dmar_iommu_to_ir(const void *section)
+json_object *cper_section_dmar_iommu_to_ir(const UINT8 *section, UINT32 size)
 {
+	if (size < sizeof(EFI_IOMMU_DMAR_ERROR_DATA)) {
+		return NULL;
+	}
+
 	EFI_IOMMU_DMAR_ERROR_DATA *iommu_error =
 		(EFI_IOMMU_DMAR_ERROR_DATA *)section;
 	json_object *section_ir = json_object_new_object();