diff --git a/MdeModulePkg/Universal/PcatRealTimeClockRuntimeDxe/PcRtc.c b/MdeModulePkg/Universal/PcatRealTimeClockRuntimeDxe/PcRtc.c index 5d52071a7b..4b1ced7439 100644 --- a/MdeModulePkg/Universal/PcatRealTimeClockRuntimeDxe/PcRtc.c +++ b/MdeModulePkg/Universal/PcatRealTimeClockRuntimeDxe/PcRtc.c @@ -888,6 +888,11 @@ DayValid ( DayOfMonth[10] = 30; DayOfMonth[11] = 31; + // + // The validity of Time->Month field should be checked before + // + ASSERT (Time->Month >=1); + ASSERT (Time->Month <=12); if (Time->Day < 1 || Time->Day > DayOfMonth[Time->Month - 1] || (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28)) @@ -1048,6 +1053,12 @@ IsWithinOneDay ( Adjacent = FALSE; + // + // The validity of Time->Month field should be checked before + // + ASSERT (From->Month >=1); + ASSERT (From->Month <=12); + if (From->Year == To->Year) { if (From->Month == To->Month) { if ((From->Day + 1) == To->Day) { diff --git a/MdeModulePkg/Universal/Variable/Pei/Ipf/VariableWorker.c b/MdeModulePkg/Universal/Variable/Pei/Ipf/VariableWorker.c index a5e0e550e3..17f152a0f1 100644 --- a/MdeModulePkg/Universal/Variable/Pei/Ipf/VariableWorker.c +++ b/MdeModulePkg/Universal/Variable/Pei/Ipf/VariableWorker.c @@ -49,7 +49,9 @@ VariableIndexTableUpdate ( IN VARIABLE_HEADER *Variable ) { - IndexTable->Index[IndexTable->Length++] = (UINT16) (((UINT32)(UINTN) Variable) >> 2); + if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME) { + IndexTable->Index[IndexTable->Length++] = (UINT16) (((UINT32)(UINTN) Variable) >> 2); + } return; } diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/Universal/Variable/Pei/Variable.c index 471b6a4749..f98d236443 100644 --- a/MdeModulePkg/Universal/Variable/Pei/Variable.c +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c @@ -443,10 +443,8 @@ FindVariable ( // // Record Variable in VariableIndex HOB // - if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME) { - VariableIndexTableUpdate (IndexTable, Variable); - } - + VariableIndexTableUpdate (IndexTable, Variable); + if (CompareWithValidVariable (Variable, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) { return EFI_SUCCESS; } diff --git a/MdeModulePkg/Universal/Variable/Pei/VariableWorker.c b/MdeModulePkg/Universal/Variable/Pei/VariableWorker.c index f9c5daa452..a99bfa8c50 100644 --- a/MdeModulePkg/Universal/Variable/Pei/VariableWorker.c +++ b/MdeModulePkg/Universal/Variable/Pei/VariableWorker.c @@ -48,7 +48,9 @@ VariableIndexTableUpdate ( IN VARIABLE_HEADER *Variable ) { - IndexTable->Index[IndexTable->Length++] = (UINT16) (UINTN) Variable; + if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME) { + IndexTable->Index[IndexTable->Length++] = (UINT16) (UINTN) Variable; + } return; }