Make all section reads const

The way sections are read currently is unsafe in two ways, first,
buffers are completely unchecked for length, and section, buffers are
passed in as non-const void*.

Start fixing things by making the sections const.

Change-Id: I02e9ded525e9710b56589a47a9cc4f3583c216df
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/include/libcper/sections/cper-section-ampere.h b/include/libcper/sections/cper-section-ampere.h
index 00b62b4..013a59f 100644
--- a/include/libcper/sections/cper-section-ampere.h
+++ b/include/libcper/sections/cper-section-ampere.h
@@ -5,7 +5,7 @@
 #include <json.h>
 #include <libcper/Cper.h>
 
-json_object *cper_section_ampere_to_ir(void *section);
+json_object *cper_section_ampere_to_ir(const void *section);
 void ir_section_ampere_to_cper(json_object *section, FILE *out);
 
 #endif
diff --git a/include/libcper/sections/cper-section-arm.h b/include/libcper/sections/cper-section-arm.h
index ebd63f1..c1c7f75 100644
--- a/include/libcper/sections/cper-section-arm.h
+++ b/include/libcper/sections/cper-section-arm.h
@@ -129,7 +129,7 @@
 			  "sctlr_el3", "sp_el3",   "spsr_el3", "tcr_el3",      \
 			  "tpidr_el3", "ttbr0_el3" }
 
-json_object *cper_section_arm_to_ir(void *section);
+json_object *cper_section_arm_to_ir(const void *section);
 void ir_section_arm_to_cper(json_object *section, FILE *out);
 
 #ifdef __cplusplus
diff --git a/include/libcper/sections/cper-section-ccix-per.h b/include/libcper/sections/cper-section-ccix-per.h
index 6ff18fc..a2b858f 100644
--- a/include/libcper/sections/cper-section-ccix-per.h
+++ b/include/libcper/sections/cper-section-ccix-per.h
@@ -24,7 +24,7 @@
 	UINT16 Reserved;
 } __attribute__((packed, aligned(1))) EFI_CCIX_PER_LOG_DATA;
 
-json_object *cper_section_ccix_per_to_ir(void *section);
+json_object *cper_section_ccix_per_to_ir(const void *section);
 void ir_section_ccix_per_to_cper(json_object *section, FILE *out);
 
 #ifdef __cplusplus
diff --git a/include/libcper/sections/cper-section-cxl-component.h b/include/libcper/sections/cper-section-cxl-component.h
index 85810a2..5f1c400 100644
--- a/include/libcper/sections/cper-section-cxl-component.h
+++ b/include/libcper/sections/cper-section-cxl-component.h
@@ -35,7 +35,7 @@
 	UINT64 DeviceSerial;
 } __attribute__((packed, aligned(1))) EFI_CXL_COMPONENT_EVENT_HEADER;
 
-json_object *cper_section_cxl_component_to_ir(void *section);
+json_object *cper_section_cxl_component_to_ir(const void *section);
 void ir_section_cxl_component_to_cper(json_object *section, FILE *out);
 
 #ifdef __cplusplus
diff --git a/include/libcper/sections/cper-section-cxl-protocol.h b/include/libcper/sections/cper-section-cxl-protocol.h
index 5cca31e..cdf23a0 100644
--- a/include/libcper/sections/cper-section-cxl-protocol.h
+++ b/include/libcper/sections/cper-section-cxl-protocol.h
@@ -63,7 +63,7 @@
 	UINT32 Reserved;
 } __attribute__((packed, aligned(1))) EFI_CXL_PROTOCOL_ERROR_DATA;
 
-json_object *cper_section_cxl_protocol_to_ir(void *section);
+json_object *cper_section_cxl_protocol_to_ir(const void *section);
 void ir_section_cxl_protocol_to_cper(json_object *section, FILE *out);
 
 #ifdef __cplusplus
diff --git a/include/libcper/sections/cper-section-dmar-generic.h b/include/libcper/sections/cper-section-dmar-generic.h
index d81dd94..a2eb08e 100644
--- a/include/libcper/sections/cper-section-dmar-generic.h
+++ b/include/libcper/sections/cper-section-dmar-generic.h
@@ -43,7 +43,7 @@
 #define DMAR_GENERIC_ERROR_ARCH_TYPES_KEYS   (int[]){ 0x0, 0x1 }
 #define DMAR_GENERIC_ERROR_ARCH_TYPES_VALUES (const char *[]){ "VT-d", "IOMMU" }
 
-json_object *cper_section_dmar_generic_to_ir(void *section);
+json_object *cper_section_dmar_generic_to_ir(const void *section);
 void ir_section_dmar_generic_to_cper(json_object *section, FILE *out);
 
 #ifdef __cplusplus
diff --git a/include/libcper/sections/cper-section-dmar-iommu.h b/include/libcper/sections/cper-section-dmar-iommu.h
index 0209dfb..9192e38 100644
--- a/include/libcper/sections/cper-section-dmar-iommu.h
+++ b/include/libcper/sections/cper-section-dmar-iommu.h
@@ -9,7 +9,7 @@
 #include <json.h>
 #include <libcper/Cper.h>
 
-json_object *cper_section_dmar_iommu_to_ir(void *section);
+json_object *cper_section_dmar_iommu_to_ir(const void *section);
 void ir_section_dmar_iommu_to_cper(json_object *section, FILE *out);
 
 #ifdef __cplusplus
diff --git a/include/libcper/sections/cper-section-dmar-vtd.h b/include/libcper/sections/cper-section-dmar-vtd.h
index 9ba1771..68a1d79 100644
--- a/include/libcper/sections/cper-section-dmar-vtd.h
+++ b/include/libcper/sections/cper-section-dmar-vtd.h
@@ -28,7 +28,7 @@
 	UINT64 Resv3 : 1;
 } EFI_VTD_FAULT_RECORD;
 
-json_object *cper_section_dmar_vtd_to_ir(void *section);
+json_object *cper_section_dmar_vtd_to_ir(const void *section);
 void ir_section_dmar_vtd_to_cper(json_object *section, FILE *out);
 
 #ifdef __cplusplus
diff --git a/include/libcper/sections/cper-section-firmware.h b/include/libcper/sections/cper-section-firmware.h
index 47e55be..fb21cfb 100644
--- a/include/libcper/sections/cper-section-firmware.h
+++ b/include/libcper/sections/cper-section-firmware.h
@@ -15,7 +15,7 @@
 			  "SOC Firmware Error Record (Type1 Legacy)",          \
 			  "SOC Firmware Error Record (Type2)" }
 
-json_object *cper_section_firmware_to_ir(void *section);
+json_object *cper_section_firmware_to_ir(const void *section);
 void ir_section_firmware_to_cper(json_object *section, FILE *out);
 
 #ifdef __cplusplus
diff --git a/include/libcper/sections/cper-section-generic.h b/include/libcper/sections/cper-section-generic.h
index 4f0d947..ac041d4 100644
--- a/include/libcper/sections/cper-section-generic.h
+++ b/include/libcper/sections/cper-section-generic.h
@@ -39,7 +39,7 @@
 #define GENERIC_FLAGS_BITFIELD_NAMES                                           \
 	(const char *[]){ "restartable", "preciseIP", "overflow", "corrected" }
 
-json_object *cper_section_generic_to_ir(void *section);
+json_object *cper_section_generic_to_ir(const void *section);
 void ir_section_generic_to_cper(json_object *section, FILE *out);
 
 #ifdef __cplusplus
diff --git a/include/libcper/sections/cper-section-ia32x64.h b/include/libcper/sections/cper-section-ia32x64.h
index 08d86ca..32f7826 100644
--- a/include/libcper/sections/cper-section-ia32x64.h
+++ b/include/libcper/sections/cper-section-ia32x64.h
@@ -74,7 +74,7 @@
 	UINT64 Reserved[2];
 } EFI_IA32_X64_CPU_ID;
 
-json_object *cper_section_ia32x64_to_ir(void *section);
+json_object *cper_section_ia32x64_to_ir(const void *section);
 void ir_section_ia32x64_to_cper(json_object *section, FILE *out);
 
 #ifdef __cplusplus
diff --git a/include/libcper/sections/cper-section-ipf.h b/include/libcper/sections/cper-section-ipf.h
index 86e396c..be985b4 100644
--- a/include/libcper/sections/cper-section-ipf.h
+++ b/include/libcper/sections/cper-section-ipf.h
@@ -65,7 +65,7 @@
 	UINT64 Frs[256];
 } EFI_IPF_PSI_STATIC;
 
-json_object *cper_section_ipf_to_ir(void *section);
+json_object *cper_section_ipf_to_ir(const void *section);
 
 #ifdef __cplusplus
 }
diff --git a/include/libcper/sections/cper-section-memory.h b/include/libcper/sections/cper-section-memory.h
index 5e88e3b..f759f1d 100644
--- a/include/libcper/sections/cper-section-memory.h
+++ b/include/libcper/sections/cper-section-memory.h
@@ -75,8 +75,8 @@
 			  "bankGroupValid",                                    \
 			  "bankAddressValid" }
 
-json_object *cper_section_platform_memory_to_ir(void *section);
-json_object *cper_section_platform_memory2_to_ir(void *section);
+json_object *cper_section_platform_memory_to_ir(const void *section);
+json_object *cper_section_platform_memory2_to_ir(const void *section);
 void ir_section_memory_to_cper(json_object *section, FILE *out);
 void ir_section_memory2_to_cper(json_object *section, FILE *out);
 
diff --git a/include/libcper/sections/cper-section-nvidia.h b/include/libcper/sections/cper-section-nvidia.h
index faed056..df85792 100644
--- a/include/libcper/sections/cper-section-nvidia.h
+++ b/include/libcper/sections/cper-section-nvidia.h
@@ -9,7 +9,7 @@
 #include <json.h>
 #include <libcper/Cper.h>
 
-json_object *cper_section_nvidia_to_ir(void *section);
+json_object *cper_section_nvidia_to_ir(const void *section);
 void ir_section_nvidia_to_cper(json_object *section, FILE *out);
 
 #ifdef __cplusplus
diff --git a/include/libcper/sections/cper-section-pci-bus.h b/include/libcper/sections/cper-section-pci-bus.h
index 9a9f34d..c4de3be 100644
--- a/include/libcper/sections/cper-section-pci-bus.h
+++ b/include/libcper/sections/cper-section-pci-bus.h
@@ -26,7 +26,7 @@
 			  "Address Parity Error",                              \
 			  "Command Parity Error" }
 
-json_object *cper_section_pci_bus_to_ir(void *section);
+json_object *cper_section_pci_bus_to_ir(const void *section);
 void ir_section_pci_bus_to_cper(json_object *section, FILE *out);
 
 #ifdef __cplusplus
diff --git a/include/libcper/sections/cper-section-pci-dev.h b/include/libcper/sections/cper-section-pci-dev.h
index 9fd283c..696a44b 100644
--- a/include/libcper/sections/cper-section-pci-dev.h
+++ b/include/libcper/sections/cper-section-pci-dev.h
@@ -36,7 +36,7 @@
 	UINT32 IoNumber;
 } __attribute__((packed, aligned(1))) EFI_PCI_PCIX_DEVICE_ERROR_DATA;
 
-json_object *cper_section_pci_dev_to_ir(void *section);
+json_object *cper_section_pci_dev_to_ir(const void *section);
 void ir_section_pci_dev_to_cper(json_object *section, FILE *out);
 
 #ifdef __cplusplus
diff --git a/include/libcper/sections/cper-section-pcie.h b/include/libcper/sections/cper-section-pcie.h
index 3d91780..05307aa 100644
--- a/include/libcper/sections/cper-section-pcie.h
+++ b/include/libcper/sections/cper-section-pcie.h
@@ -30,7 +30,7 @@
 			  "Root Complex Integrated Endpoint Device",           \
 			  "Root Complex Event Collector" }
 
-json_object *cper_section_pcie_to_ir(void *section);
+json_object *cper_section_pcie_to_ir(const void *section);
 void ir_section_pcie_to_cper(json_object *section, FILE *out);
 
 #ifdef __cplusplus
diff --git a/include/libcper/sections/cper-section.h b/include/libcper/sections/cper-section.h
index f288f2a..5874edf 100644
--- a/include/libcper/sections/cper-section.h
+++ b/include/libcper/sections/cper-section.h
@@ -15,7 +15,7 @@
 	EFI_GUID *Guid;
 	const char *ReadableName;
 	const char *ShortName;
-	json_object *(*ToIR)(void *);
+	json_object *(*ToIR)(const void *);
 	void (*ToCPER)(json_object *, FILE *);
 } CPER_SECTION_DEFINITION;
 
diff --git a/sections/cper-section-ampere.c b/sections/cper-section-ampere.c
index 7604dc0..5002a26 100644
--- a/sections/cper-section-ampere.c
+++ b/sections/cper-section-ampere.c
@@ -5,7 +5,7 @@
 #include <libcper/sections/cper-section-ampere.h>
 
 //Converts the given processor-generic CPER section into JSON IR.
-json_object *cper_section_ampere_to_ir(void *section)
+json_object *cper_section_ampere_to_ir(const void *section)
 {
 	EFI_AMPERE_ERROR_DATA *record = (EFI_AMPERE_ERROR_DATA *)section;
 	json_object *section_ir = json_object_new_object();
diff --git a/sections/cper-section-arm.c b/sections/cper-section-arm.c
index 067c4f8..31fa9b0 100644
--- a/sections/cper-section-arm.c
+++ b/sections/cper-section-arm.c
@@ -44,7 +44,7 @@
 void ir_arm_unknown_register_to_cper(json_object *registers, FILE *out);
 
 //Converts the given processor-generic CPER section into JSON IR.
-json_object *cper_section_arm_to_ir(void *section)
+json_object *cper_section_arm_to_ir(const void *section)
 {
 	EFI_ARM_ERROR_RECORD *record = (EFI_ARM_ERROR_RECORD *)section;
 	json_object *section_ir = json_object_new_object();
diff --git a/sections/cper-section-ccix-per.c b/sections/cper-section-ccix-per.c
index 6f85939..a4cab0c 100644
--- a/sections/cper-section-ccix-per.c
+++ b/sections/cper-section-ccix-per.c
@@ -13,7 +13,7 @@
 #include <libcper/sections/cper-section-ccix-per.h>
 
 //Converts a single CCIX PER log CPER section into JSON IR.
-json_object *cper_section_ccix_per_to_ir(void *section)
+json_object *cper_section_ccix_per_to_ir(const void *section)
 {
 	EFI_CCIX_PER_LOG_DATA *ccix_error = (EFI_CCIX_PER_LOG_DATA *)section;
 	json_object *section_ir = json_object_new_object();
diff --git a/sections/cper-section-cxl-component.c b/sections/cper-section-cxl-component.c
index f915b28..f1db9ad 100644
--- a/sections/cper-section-cxl-component.c
+++ b/sections/cper-section-cxl-component.c
@@ -12,7 +12,7 @@
 #include <libcper/sections/cper-section-cxl-component.h>
 
 //Converts a single CXL component error CPER section into JSON IR.
-json_object *cper_section_cxl_component_to_ir(void *section)
+json_object *cper_section_cxl_component_to_ir(const void *section)
 {
 	EFI_CXL_COMPONENT_EVENT_HEADER *cxl_error =
 		(EFI_CXL_COMPONENT_EVENT_HEADER *)section;
diff --git a/sections/cper-section-cxl-protocol.c b/sections/cper-section-cxl-protocol.c
index 151943f..4b5737b 100644
--- a/sections/cper-section-cxl-protocol.c
+++ b/sections/cper-section-cxl-protocol.c
@@ -12,7 +12,7 @@
 #include <libcper/sections/cper-section-cxl-protocol.h>
 
 //Converts a single CXL protocol error CPER section into JSON IR.
-json_object *cper_section_cxl_protocol_to_ir(void *section)
+json_object *cper_section_cxl_protocol_to_ir(const void *section)
 {
 	EFI_CXL_PROTOCOL_ERROR_DATA *cxl_protocol_error =
 		(EFI_CXL_PROTOCOL_ERROR_DATA *)section;
diff --git a/sections/cper-section-dmar-generic.c b/sections/cper-section-dmar-generic.c
index 9e5f06a..7468d30 100644
--- a/sections/cper-section-dmar-generic.c
+++ b/sections/cper-section-dmar-generic.c
@@ -11,7 +11,7 @@
 #include <libcper/sections/cper-section-dmar-generic.h>
 
 //Converts a single generic DMAr CPER section into JSON IR.
-json_object *cper_section_dmar_generic_to_ir(void *section)
+json_object *cper_section_dmar_generic_to_ir(const void *section)
 {
 	EFI_DMAR_GENERIC_ERROR_DATA *firmware_error =
 		(EFI_DMAR_GENERIC_ERROR_DATA *)section;
diff --git a/sections/cper-section-dmar-iommu.c b/sections/cper-section-dmar-iommu.c
index 1f08376..99af77c 100644
--- a/sections/cper-section-dmar-iommu.c
+++ b/sections/cper-section-dmar-iommu.c
@@ -13,7 +13,7 @@
 #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(void *section)
+json_object *cper_section_dmar_iommu_to_ir(const void *section)
 {
 	EFI_IOMMU_DMAR_ERROR_DATA *iommu_error =
 		(EFI_IOMMU_DMAR_ERROR_DATA *)section;
diff --git a/sections/cper-section-dmar-vtd.c b/sections/cper-section-dmar-vtd.c
index 5c0016b..16985a9 100644
--- a/sections/cper-section-dmar-vtd.c
+++ b/sections/cper-section-dmar-vtd.c
@@ -13,7 +13,7 @@
 #include <libcper/sections/cper-section-dmar-vtd.h>
 
 //Converts a single VT-d specific DMAr CPER section into JSON IR.
-json_object *cper_section_dmar_vtd_to_ir(void *section)
+json_object *cper_section_dmar_vtd_to_ir(const void *section)
 {
 	EFI_DIRECTED_IO_DMAR_ERROR_DATA *vtd_error =
 		(EFI_DIRECTED_IO_DMAR_ERROR_DATA *)section;
diff --git a/sections/cper-section-firmware.c b/sections/cper-section-firmware.c
index 7316295..ebdc11f 100644
--- a/sections/cper-section-firmware.c
+++ b/sections/cper-section-firmware.c
@@ -11,7 +11,7 @@
 #include <libcper/sections/cper-section-firmware.h>
 
 //Converts a single firmware CPER section into JSON IR.
-json_object *cper_section_firmware_to_ir(void *section)
+json_object *cper_section_firmware_to_ir(const void *section)
 {
 	EFI_FIRMWARE_ERROR_DATA *firmware_error =
 		(EFI_FIRMWARE_ERROR_DATA *)section;
diff --git a/sections/cper-section-generic.c b/sections/cper-section-generic.c
index 36a5d89..7bbf56e 100644
--- a/sections/cper-section-generic.c
+++ b/sections/cper-section-generic.c
@@ -13,7 +13,7 @@
 #include <libcper/sections/cper-section-generic.h>
 
 //Converts the given processor-generic CPER section into JSON IR.
-json_object *cper_section_generic_to_ir(void *section)
+json_object *cper_section_generic_to_ir(const void *section)
 {
 	EFI_PROCESSOR_GENERIC_ERROR_DATA *section_generic =
 		(EFI_PROCESSOR_GENERIC_ERROR_DATA *)section;
diff --git a/sections/cper-section-ia32x64.c b/sections/cper-section-ia32x64.c
index 8e89ee3..f217612 100644
--- a/sections/cper-section-ia32x64.c
+++ b/sections/cper-section-ia32x64.c
@@ -43,7 +43,7 @@
 //////////////////
 
 //Converts the IA32/x64 error section described in the given descriptor into intermediate format.
-json_object *cper_section_ia32x64_to_ir(void *section)
+json_object *cper_section_ia32x64_to_ir(const void *section)
 {
 	EFI_IA32_X64_PROCESSOR_ERROR_RECORD *record =
 		(EFI_IA32_X64_PROCESSOR_ERROR_RECORD *)section;
diff --git a/sections/cper-section-ipf.c b/sections/cper-section-ipf.c
index a8a4e8f..a50cfab 100644
--- a/sections/cper-section-ipf.c
+++ b/sections/cper-section-ipf.c
@@ -15,7 +15,7 @@
 json_object *cper_ipf_mod_error_to_ir(EFI_IPF_MOD_ERROR_INFO *mod_error);
 
 //Converts a single Intel IPF error CPER section into JSON IR.
-json_object *cper_section_ipf_to_ir(void *section)
+json_object *cper_section_ipf_to_ir(const void *section)
 {
 	EFI_IPF_ERROR_INFO_HEADER *ipf_error =
 		(EFI_IPF_ERROR_INFO_HEADER *)section;
diff --git a/sections/cper-section-memory.c b/sections/cper-section-memory.c
index ce9119d..c5a2094 100644
--- a/sections/cper-section-memory.c
+++ b/sections/cper-section-memory.c
@@ -11,7 +11,7 @@
 #include <libcper/sections/cper-section-memory.h>
 
 //Converts a single memory error CPER section into JSON IR.
-json_object *cper_section_platform_memory_to_ir(void *section)
+json_object *cper_section_platform_memory_to_ir(const void *section)
 {
 	EFI_PLATFORM_MEMORY_ERROR_DATA *memory_error =
 		(EFI_PLATFORM_MEMORY_ERROR_DATA *)section;
@@ -166,7 +166,7 @@
 }
 
 //Converts a single memory error 2 CPER section into JSON IR.
-json_object *cper_section_platform_memory2_to_ir(void *section)
+json_object *cper_section_platform_memory2_to_ir(const void *section)
 {
 	EFI_PLATFORM_MEMORY2_ERROR_DATA *memory_error =
 		(EFI_PLATFORM_MEMORY2_ERROR_DATA *)section;
diff --git a/sections/cper-section-nvidia.c b/sections/cper-section-nvidia.c
index d5587c5..8b211ea 100644
--- a/sections/cper-section-nvidia.c
+++ b/sections/cper-section-nvidia.c
@@ -12,7 +12,7 @@
 #include <libcper/sections/cper-section-nvidia.h>
 
 //Converts a single NVIDIA CPER section into JSON IR.
-json_object *cper_section_nvidia_to_ir(void *section)
+json_object *cper_section_nvidia_to_ir(const void *section)
 {
 	EFI_NVIDIA_ERROR_DATA *nvidia_error = (EFI_NVIDIA_ERROR_DATA *)section;
 	json_object *section_ir = json_object_new_object();
diff --git a/sections/cper-section-pci-bus.c b/sections/cper-section-pci-bus.c
index 2884f61..5564c21 100644
--- a/sections/cper-section-pci-bus.c
+++ b/sections/cper-section-pci-bus.c
@@ -12,7 +12,7 @@
 #include <libcper/sections/cper-section-pci-bus.h>
 
 //Converts a single PCI/PCI-X bus CPER section into JSON IR.
-json_object *cper_section_pci_bus_to_ir(void *section)
+json_object *cper_section_pci_bus_to_ir(const void *section)
 {
 	EFI_PCI_PCIX_BUS_ERROR_DATA *bus_error =
 		(EFI_PCI_PCIX_BUS_ERROR_DATA *)section;
diff --git a/sections/cper-section-pci-dev.c b/sections/cper-section-pci-dev.c
index 8dc899b..adc54a0 100644
--- a/sections/cper-section-pci-dev.c
+++ b/sections/cper-section-pci-dev.c
@@ -11,7 +11,7 @@
 #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(void *section)
+json_object *cper_section_pci_dev_to_ir(const void *section)
 {
 	EFI_PCI_PCIX_DEVICE_ERROR_DATA *dev_error =
 		(EFI_PCI_PCIX_DEVICE_ERROR_DATA *)section;
diff --git a/sections/cper-section-pcie.c b/sections/cper-section-pcie.c
index 05c1a53..5e83f9d 100644
--- a/sections/cper-section-pcie.c
+++ b/sections/cper-section-pcie.c
@@ -24,7 +24,7 @@
 };
 
 //Converts a single PCIe CPER section into JSON IR.
-json_object *cper_section_pcie_to_ir(void *section)
+json_object *cper_section_pcie_to_ir(const void *section)
 {
 	EFI_PCIE_ERROR_DATA *pcie_error = (EFI_PCIE_ERROR_DATA *)section;
 	json_object *section_ir = json_object_new_object();