When read a variable in PEI, it will find it first in the HOB, then find in variable store. When find in variable store, it will check the variable state, but find in HOB, it doesn't check the state, so if the variable was changed, it will find the obsolete variable in the HOB. Signed-off-by: jdzhang --- MdeModulePkg/Universal/Variable/Pei/Variable.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/Universal/Variable/Pei/Variable.c index 26a4c73b45..dffbd8cdb1 100644 --- a/MdeModulePkg/Universal/Variable/Pei/Variable.c +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c @@ -866,11 +866,13 @@ FindVariableEx ( Offset  += IndexTable->Index[Index]; MaxIndex = (VARIABLE_HEADER *)((UINT8 *)IndexTable->StartPtr + Offset); GetVariableHeader (StoreInfo, MaxIndex, &VariableHeader); -      if (CompareWithValidVariable (StoreInfo, MaxIndex, VariableHeader, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) { -        if (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) { -          InDeletedVariable = PtrTrack->CurrPtr; -        } else { -          return EFI_SUCCESS; +      if ((VariableHeader->State == VAR_ADDED) || (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED))) { +        if (CompareWithValidVariable (StoreInfo, MaxIndex, VariableHeader, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) { +          if (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) { +            InDeletedVariable = PtrTrack->CurrPtr; +          } else { +            return EFI_SUCCESS; +          } } } } -- 2.20.1.windows.1