QcomModulePkg: Validating values for num_ranks and num_channels variables
Adding constraint to check variables num_ranks and num_channels doesn't
have value more than maximum allowed.
Change-Id: I4d362def08561f527ebdf03113f32768570575b6
diff --git a/QcomModulePkg/Library/BootLib/UpdateDeviceTree.c b/QcomModulePkg/Library/BootLib/UpdateDeviceTree.c
index 349d19d..cf2ca6f 100644
--- a/QcomModulePkg/Library/BootLib/UpdateDeviceTree.c
+++ b/QcomModulePkg/Library/BootLib/UpdateDeviceTree.c
@@ -91,6 +91,18 @@
DEBUG ((EFI_D_ERROR, "INFO: GetDDR details failed\n"));
return Status;
}
+
+ if (DdrInfo->num_channels > MAX_CHANNELS) {
+ DEBUG ((EFI_D_ERROR, "ERROR: Number of channels is over the limit\n"));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ for (UINT8 Chan = 0; Chan < DdrInfo->num_channels; Chan++) {
+ if (DdrInfo->num_ranks[Chan] > MAX_RANKS) {
+ DEBUG ((EFI_D_ERROR, "ERROR: Number of ranks is over the limit\n"));
+ return EFI_INVALID_PARAMETER;
+ }
+ }
*Revision = DdrInfoIf->Revision;
DEBUG ((EFI_D_VERBOSE, "DDR Header Revision =0x%x\n", *Revision));
return Status;