\r
This code checks if variable header is valid or not.\r
\r
- @param Variable Pointer to the Variable Header.\r
+ @param Variable Pointer to the Variable Header.\r
+ @param VariableStoreEnd Pointer to the Variable Store End.\r
\r
- @retval TRUE Variable header is valid.\r
- @retval FALSE Variable header is not valid.\r
+ @retval TRUE Variable header is valid.\r
+ @retval FALSE Variable header is not valid.\r
\r
**/\r
BOOLEAN\r
IsValidVariableHeader (\r
- IN VARIABLE_HEADER *Variable\r
+ IN VARIABLE_HEADER *Variable,\r
+ IN VARIABLE_HEADER *VariableStoreEnd\r
)\r
{\r
- if (Variable == NULL || Variable->StartId != VARIABLE_DATA) {\r
+ if ((Variable == NULL) || (Variable >= VariableStoreEnd) || (Variable->StartId != VARIABLE_DATA)) {\r
+ //\r
+ // Variable is NULL or has reached the end of variable store,\r
+ // or the StartId is not correct.\r
+ //\r
return FALSE;\r
}\r
\r
{\r
UINTN Value;\r
\r
- if (!IsValidVariableHeader (Variable)) {\r
- return NULL;\r
- }\r
-\r
Value = (UINTN) GetVariableDataPtr (Variable);\r
Value += DataSizeOfVariable (Variable);\r
Value += GET_PAD_SIZE (DataSizeOfVariable (Variable));\r
\r
Check the PubKeyIndex is a valid key or not.\r
\r
- This function will iterate the NV storage to see if this PubKeyIndex is still referenced \r
+ This function will iterate the NV storage to see if this PubKeyIndex is still referenced\r
by any valid count-based auth variabe.\r
- \r
+\r
@param[in] PubKeyIndex Index of the public key in public key store.\r
\r
@retval TRUE The PubKeyIndex is still in use.\r
@retval FALSE The PubKeyIndex is not referenced by any count-based auth variabe.\r
- \r
+\r
**/\r
BOOLEAN\r
IsValidPubKeyIndex (\r
)\r
{\r
VARIABLE_HEADER *Variable;\r
+ VARIABLE_HEADER *VariableStoreEnd;\r
\r
if (PubKeyIndex > mPubKeyNumber) {\r
return FALSE;\r
}\r
- \r
+\r
Variable = GetStartPointer ((VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);\r
- \r
- while (IsValidVariableHeader (Variable)) {\r
- if ((Variable->State == VAR_ADDED || Variable->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) && \r
+ VariableStoreEnd = GetEndPointer ((VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);\r
+\r
+ while (IsValidVariableHeader (Variable, VariableStoreEnd)) {\r
+ if ((Variable->State == VAR_ADDED || Variable->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) &&\r
Variable->PubKeyIndex == PubKeyIndex) {\r
return TRUE;\r
}\r
Variable = GetNextVariablePtr (Variable);\r
}\r
- \r
+\r
return FALSE;\r
}\r
\r
/**\r
\r
Get the number of valid public key in PubKeyStore.\r
- \r
+\r
@param[in] PubKeyNumber Number of the public key in public key store.\r
\r
@return Number of valid public key in PubKeyStore.\r
UINT32 Counter;\r
\r
Counter = 0;\r
- \r
+\r
for (PubKeyIndex = 1; PubKeyIndex <= PubKeyNumber; PubKeyIndex++) {\r
if (IsValidPubKeyIndex (PubKeyIndex)) {\r
Counter++;\r
}\r
}\r
- \r
+\r
return Counter;\r
}\r
\r
\r
Filter the useless key in public key store.\r
\r
- This function will find out all valid public keys in public key database, save them in new allocated \r
+ This function will find out all valid public keys in public key database, save them in new allocated\r
buffer NewPubKeyStore, and give the new PubKeyIndex. The caller is responsible for freeing buffer\r
NewPubKeyIndex and NewPubKeyStore with FreePool().\r
\r
@param[out] NewPubKeyIndex Point to an array of new PubKeyIndex corresponds to NewPubKeyStore.\r
@param[out] NewPubKeyStore Saved all valid public keys in PubKeyStore.\r
@param[out] NewPubKeySize Buffer size of the NewPubKeyStore.\r
- \r
+\r
@retval EFI_SUCCESS Trim operation is complete successfully.\r
@retval EFI_OUT_OF_RESOURCES No enough memory resources, or no useless key in PubKeyStore.\r
- \r
+\r
**/\r
EFI_STATUS\r
PubKeyStoreFilter (\r
UINT32 PubKeyIndex;\r
UINT32 CopiedKey;\r
UINT32 NewPubKeyNumber;\r
- \r
+\r
NewPubKeyNumber = GetValidPubKeyNumber (PubKeyNumber);\r
if (NewPubKeyNumber == PubKeyNumber) {\r
return EFI_OUT_OF_RESOURCES;\r
@param[in] NewVariable Pointer to new variable.\r
@param[in] NewVariableSize New variable size.\r
@param[in] ReclaimPubKeyStore Reclaim for public key database or not.\r
- \r
+\r
@return EFI_SUCCESS Reclaim operation has finished successfully.\r
@return EFI_OUT_OF_RESOURCES No enough memory resources or variable space.\r
@return EFI_DEVICE_ERROR The public key database doesn't exist.\r
Variable = GetStartPointer (VariableStoreHeader);\r
MaximumBufferSize = sizeof (VARIABLE_STORE_HEADER);\r
\r
- while (IsValidVariableHeader (Variable)) {\r
+ while (IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHeader))) {\r
NextVariable = GetNextVariablePtr (Variable);\r
if ((Variable->State == VAR_ADDED || Variable->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) &&\r
Variable != UpdatingVariable &&\r
// Refresh the PubKeyIndex for all valid variables (ADDED and IN_DELETED_TRANSITION).\r
//\r
Variable = GetStartPointer (VariableStoreHeader);\r
- while (IsValidVariableHeader (Variable)) {\r
+ while (IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHeader))) {\r
NextVariable = GetNextVariablePtr (Variable);\r
if (Variable->State == VAR_ADDED || Variable->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {\r
- if ((StrCmp (GetVariableNamePtr (Variable), AUTHVAR_KEYDB_NAME) == 0) && \r
+ if ((StrCmp (GetVariableNamePtr (Variable), AUTHVAR_KEYDB_NAME) == 0) &&\r
(CompareGuid (&Variable->VendorGuid, &gEfiAuthenticatedVariableGuid))) {\r
//\r
// Skip the public key database, it will be reinstalled later.\r
Variable = NextVariable;\r
continue;\r
}\r
- \r
+\r
VariableSize = (UINTN) NextVariable - (UINTN) Variable;\r
CopyMem (CurrPtr, (UINT8 *) Variable, VariableSize);\r
((VARIABLE_HEADER*) CurrPtr)->PubKeyIndex = NewPubKeyIndex[Variable->PubKeyIndex];\r
Variable->DataSize = NewPubKeySize;\r
StrCpy (GetVariableNamePtr (Variable), GetVariableNamePtr (PubKeyHeader));\r
CopyMem (GetVariableDataPtr (Variable), NewPubKeyStore, NewPubKeySize);\r
- CurrPtr = (UINT8*) GetNextVariablePtr (Variable); \r
+ CurrPtr = (UINT8*) GetNextVariablePtr (Variable);\r
CommonVariableTotalSize += (UINTN) CurrPtr - (UINTN) Variable;\r
} else {\r
//\r
// Reinstall all ADDED variables as long as they are not identical to Updating Variable.\r
//\r
Variable = GetStartPointer (VariableStoreHeader);\r
- while (IsValidVariableHeader (Variable)) {\r
+ while (IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHeader))) {\r
NextVariable = GetNextVariablePtr (Variable);\r
if (Variable != UpdatingVariable && Variable->State == VAR_ADDED) {\r
VariableSize = (UINTN) NextVariable - (UINTN) Variable;\r
// Reinstall all in delete transition variables.\r
//\r
Variable = GetStartPointer (VariableStoreHeader);\r
- while (IsValidVariableHeader (Variable)) {\r
+ while (IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHeader))) {\r
NextVariable = GetNextVariablePtr (Variable);\r
if (Variable != UpdatingVariable && Variable != UpdatingInDeletedTransition && Variable->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {\r
\r
\r
FoundAdded = FALSE;\r
AddedVariable = GetStartPointer ((VARIABLE_STORE_HEADER *) ValidBuffer);\r
- while (IsValidVariableHeader (AddedVariable)) {\r
+ while (IsValidVariableHeader (AddedVariable, GetEndPointer ((VARIABLE_STORE_HEADER *) ValidBuffer))) {\r
NextAddedVariable = GetNextVariablePtr (AddedVariable);\r
NameSize = NameSizeOfVariable (AddedVariable);\r
if (CompareGuid (&AddedVariable->VendorGuid, &Variable->VendorGuid) &&\r
mVariableModuleGlobal->CommonVariableTotalSize = CommonVariableTotalSize;\r
} else {\r
NextVariable = GetStartPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableBase);\r
- while (IsValidVariableHeader (NextVariable)) {\r
+ while (IsValidVariableHeader (NextVariable, GetEndPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableBase))) {\r
VariableSize = NextVariable->NameSize + NextVariable->DataSize + sizeof (VARIABLE_HEADER);\r
if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {\r
mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN (VariableSize);\r
InDeletedVariable = NULL;\r
\r
for ( PtrTrack->CurrPtr = PtrTrack->StartPtr\r
- ; (PtrTrack->CurrPtr < PtrTrack->EndPtr) && IsValidVariableHeader (PtrTrack->CurrPtr)\r
+ ; IsValidVariableHeader (PtrTrack->CurrPtr, PtrTrack->EndPtr)\r
; PtrTrack->CurrPtr = GetNextVariablePtr (PtrTrack->CurrPtr)\r
) {\r
if (PtrTrack->CurrPtr->State == VAR_ADDED ||\r
\r
@param[in] Attributes Variable attributes for Variable entries.\r
@param ... The variable argument list with type VARIABLE_ENTRY_CONSISTENCY *.\r
- A NULL terminates the list. The VariableSize of \r
+ A NULL terminates the list. The VariableSize of\r
VARIABLE_ENTRY_CONSISTENCY is the variable data size as input.\r
It will be changed to variable total size as output.\r
\r
VariableEntry[0].VariableSize = ISO_639_2_ENTRY_SIZE + 1;\r
VariableEntry[0].Guid = &gEfiGlobalVariableGuid;\r
VariableEntry[0].Name = EFI_LANG_VARIABLE_NAME;\r
- \r
+\r
VariableEntry[1].VariableSize = AsciiStrSize (BestPlatformLang);\r
VariableEntry[1].Guid = &gEfiGlobalVariableGuid;\r
VariableEntry[1].Name = EFI_PLATFORM_LANG_VARIABLE_NAME;\r
Status = EFI_INVALID_PARAMETER;\r
goto Done;\r
}\r
- \r
+\r
//\r
// Only variable that have RT attributes can be updated/deleted in Runtime.\r
//\r
CopyMem (BufferForMerge, (UINT8 *) ((UINTN) Variable->CurrPtr + DataOffset), Variable->CurrPtr->DataSize);\r
\r
//\r
- // Set Max Common Variable Data Size as default MaxDataSize \r
+ // Set Max Common Variable Data Size as default MaxDataSize\r
//\r
MaxDataSize = PcdGet32 (PcdMaxVariableSize) - DataOffset;\r
\r
if ((CompareGuid (VendorGuid, &gEfiImageSecurityDatabaseGuid) &&\r
- ((StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE) == 0) || (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE1) == 0))) ||\r
- (CompareGuid (VendorGuid, &gEfiGlobalVariableGuid) && (StrCmp (VariableName, EFI_KEY_EXCHANGE_KEY_NAME) == 0))) {\r
+ ((StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE) == 0) || (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE1) == 0) ||\r
+ (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE2) == 0))) ||\r
+ (CompareGuid (VendorGuid, &gEfiGlobalVariableGuid) && (StrCmp (VariableName, EFI_KEY_EXCHANGE_KEY_NAME) == 0))) {\r
//\r
// For variables with formatted as EFI_SIGNATURE_LIST, the driver shall not perform an append of\r
// EFI_SIGNATURE_DATA values that are already part of the existing variable value.\r
//\r
Status = AppendSignatureList (\r
BufferForMerge,\r
- Variable->CurrPtr->DataSize, \r
+ Variable->CurrPtr->DataSize,\r
MaxDataSize - Variable->CurrPtr->DataSize,\r
Data,\r
DataSize,\r
/**\r
Check if a Unicode character is a hexadecimal character.\r
\r
- This function checks if a Unicode character is a \r
- hexadecimal character. The valid hexadecimal character is \r
+ This function checks if a Unicode character is a\r
+ hexadecimal character. The valid hexadecimal character is\r
L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r
\r
\r
\r
@retval TRUE This variable is read-only variable.\r
@retval FALSE This variable is NOT read-only variable.\r
- \r
+\r
**/\r
BOOLEAN\r
IsReadOnlyVariable (\r
return TRUE;\r
}\r
}\r
- \r
+\r
return FALSE;\r
}\r
\r
//\r
// Switch from Volatile to HOB, to Non-Volatile.\r
//\r
- while ((Variable.CurrPtr >= Variable.EndPtr) ||\r
- (Variable.CurrPtr == NULL) ||\r
- !IsValidVariableHeader (Variable.CurrPtr)\r
- ) {\r
+ while (!IsValidVariableHeader (Variable.CurrPtr, Variable.EndPtr)) {\r
//\r
// Find current storage index\r
//\r
\r
if ((UINTN)(~0) - PayloadSize < StrSize(VariableName)){\r
//\r
- // Prevent whole variable size overflow \r
- // \r
+ // Prevent whole variable size overflow\r
+ //\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
// Parse non-volatile variable data and get last variable offset.\r
//\r
NextVariable = GetStartPointer ((VARIABLE_STORE_HEADER *) (UINTN) Point);\r
- while ((NextVariable < GetEndPointer ((VARIABLE_STORE_HEADER *) (UINTN) Point))\r
- && IsValidVariableHeader (NextVariable)) {\r
+ while (IsValidVariableHeader (NextVariable, GetEndPointer ((VARIABLE_STORE_HEADER *) (UINTN) Point))) {\r
NextVariable = GetNextVariablePtr (NextVariable);\r
}\r
mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) NextVariable - (UINTN) Point;\r
Status = ProcessVarWithPk (VariableName, VendorGuid, Data, DataSize, &Variable, Attributes, TRUE);\r
} else if (CompareGuid (VendorGuid, &gEfiGlobalVariableGuid) && (StrCmp (VariableName, EFI_KEY_EXCHANGE_KEY_NAME) == 0)) {\r
Status = ProcessVarWithPk (VariableName, VendorGuid, Data, DataSize, &Variable, Attributes, FALSE);\r
- } else if (CompareGuid (VendorGuid, &gEfiImageSecurityDatabaseGuid) && \r
- ((StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE) == 0) || (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE1) == 0))) {\r
+ } else if (CompareGuid (VendorGuid, &gEfiImageSecurityDatabaseGuid) &&\r
+ ((StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE) == 0) || (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE1) == 0))\r
+ || (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE2)) == 0) {\r
Status = ProcessVarWithPk (VariableName, VendorGuid, Data, DataSize, &Variable, Attributes, FALSE);\r
if (EFI_ERROR (Status)) {\r
Status = ProcessVarWithKek (VariableName, VendorGuid, Data, DataSize, &Variable, Attributes);\r
//\r
// Now walk through the related variable store.\r
//\r
- while ((Variable < GetEndPointer (VariableStoreHeader)) && IsValidVariableHeader (Variable)) {\r
+ while (IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHeader))) {\r
NextVariable = GetNextVariablePtr (Variable);\r
VariableSize = (UINT64) (UINTN) NextVariable - (UINT64) (UINTN) Variable;\r
\r
// Parse non-volatile variable data and get last variable offset.\r
//\r
NextVariable = GetStartPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase);\r
- while (IsValidVariableHeader (NextVariable)) {\r
+ while (IsValidVariableHeader (NextVariable, GetEndPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase))) {\r
VariableSize = NextVariable->NameSize + NextVariable->DataSize + sizeof (VARIABLE_HEADER);\r
if ((NextVariable->Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {\r
mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN (VariableSize);\r
//\r
mVariableModuleGlobal->VariableGlobal.HobVariableBase = 0;\r
for ( Variable = GetStartPointer (VariableStoreHeader)\r
- ; (Variable < GetEndPointer (VariableStoreHeader) && IsValidVariableHeader (Variable))\r
+ ; IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHeader))\r
; Variable = GetNextVariablePtr (Variable)\r
) {\r
if (Variable->State != VAR_ADDED) {\r
\r
return Status;\r
}\r
-\r