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-pci-dev.c b/sections/cper-section-pci-dev.c
index adc54a0..9f89494 100644
--- a/sections/cper-section-pci-dev.c
+++ b/sections/cper-section-pci-dev.c
@@ -11,10 +11,21 @@
#include <libcper/sections/cper-section-pci-dev.h>
//Converts a single PCI/PCI-X device CPER section into JSON IR.
-json_object *cper_section_pci_dev_to_ir(const void *section)
+json_object *cper_section_pci_dev_to_ir(const UINT8 *section, UINT32 size)
{
+ if (size < sizeof(EFI_PCI_PCIX_DEVICE_ERROR_DATA)) {
+ return NULL;
+ }
+
EFI_PCI_PCIX_DEVICE_ERROR_DATA *dev_error =
(EFI_PCI_PCIX_DEVICE_ERROR_DATA *)section;
+
+ if (size < sizeof(EFI_PCI_PCIX_DEVICE_ERROR_DATA) +
+ ((dev_error->MemoryNumber + dev_error->IoNumber) *
+ sizeof(EFI_PCI_PCIX_DEVICE_ERROR_DATA_REGISTER))) {
+ return NULL;
+ }
+
json_object *section_ir = json_object_new_object();
//Validation bits.