X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FVariable%2FPei%2FVariable.c;h=18e252f97312fdcd027b353e2abb01183af94ae7;hp=d1165e1fe599af6407e76e8e14a9d1e08dd46b92;hb=fe1e36e550c6ffcd2561903d434683d3939e1942;hpb=ab5f0d6d1271a293979af569a269792c491d0893 diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/Universal/Variable/Pei/Variable.c index d1165e1fe5..18e252f973 100644 --- a/MdeModulePkg/Universal/Variable/Pei/Variable.c +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c @@ -1,6 +1,9 @@ -/*++ +/** @file + + Implement ReadOnly Variable Services required by PEIM and install + PI ReadOnly Varaiable2 PPI. These services operates the non volatile storage space. -Copyright (c) 2006 - 2007 Intel Corporation.
+Copyright (c) 2006 - 2008 Intel Corporation.
All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -10,13 +13,7 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Module Name: - Variable.c - -Abstract: - - PEIM to provide the Variable functionality - ---*/ +**/ #include "Variable.h" @@ -24,12 +21,12 @@ Abstract: // // Module globals // -static EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariablePpi = { +EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariablePpi = { PeiGetVariable, PeiGetNextVariableName }; -static EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = { +EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = { (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), &gEfiPeiReadOnlyVariable2PpiGuid, &mVariablePpi @@ -120,10 +117,10 @@ Returns: return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarStoreHeader->Size); } -STATIC -VARIABLE_HEADER * -GetNextVariablePtr ( - IN VARIABLE_HEADER *Variable +BOOLEAN +EFIAPI +IsValidVariableHeader ( + IN VARIABLE_HEADER *Variable ) /*++ @@ -132,7 +129,7 @@ Routine Description: This code checks if variable header is valid or not. Arguments: - Variable Pointer to the Variable Header. + Variable Pointer to the Variable Header. Returns: TRUE Variable header is valid. @@ -140,38 +137,166 @@ Returns: --*/ { - return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) GET_VARIABLE_DATA_PTR (Variable) + DATASIZE_OF_VARIABLE (Variable) + GET_PAD_SIZE (DATASIZE_OF_VARIABLE (Variable))); + if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) { + return FALSE; + } + + return TRUE; } -STATIC -BOOLEAN -EFIAPI -IsValidVariableHeader ( + +UINTN +NameSizeOfVariable ( IN VARIABLE_HEADER *Variable ) /*++ Routine Description: - This code checks if variable header is valid or not. + This code gets the size of name of variable. + +Arguments: + + Variable Pointer to the Variable Header. + +Returns: + + UINTN Size of variable in bytes + +--*/ +{ + if (Variable->State == (UINT8) (-1) || + Variable->DataSize == (UINT32) -1 || + Variable->NameSize == (UINT32) -1 || + Variable->Attributes == (UINT32) -1) { + return 0; + } + return (UINTN) Variable->NameSize; +} + +UINTN +DataSizeOfVariable ( + IN VARIABLE_HEADER *Variable + ) +/*++ + +Routine Description: + + This code gets the size of name of variable. + +Arguments: + + Variable Pointer to the Variable Header. + +Returns: + + UINTN Size of variable in bytes + +--*/ +{ + if (Variable->State == (UINT8) -1 || + Variable->DataSize == (UINT32) -1 || + Variable->NameSize == (UINT32) -1 || + Variable->Attributes == (UINT32) -1) { + return 0; + } + return (UINTN) Variable->DataSize; +} + +CHAR16 * +GetVariableNamePtr ( + IN VARIABLE_HEADER *Variable + ) +/*++ + +Routine Description: + + This code gets the pointer to the variable name. + +Arguments: + + Variable Pointer to the Variable Header. + +Returns: + + CHAR16* Pointer to Variable Name + +--*/ +{ + + return (CHAR16 *) (Variable + 1); +} + + +UINT8 * +GetVariableDataPtr ( + IN VARIABLE_HEADER *Variable + ) +/*++ + +Routine Description: + + This code gets the pointer to the variable data. Arguments: + + Variable Pointer to the Variable Header. + +Returns: + + UINT8* Pointer to Variable Data + +--*/ +{ + UINTN Value; + + // + // Be careful about pad size for alignment + // + Value = (UINTN) GetVariableNamePtr (Variable); + Value += NameSizeOfVariable (Variable); + Value += GET_PAD_SIZE (NameSizeOfVariable (Variable)); + + return (UINT8 *) Value; +} + +VARIABLE_HEADER * +GetNextVariablePtr ( + IN VARIABLE_HEADER *Variable + ) +/*++ + +Routine Description: + + This code gets the pointer to the next variable header. + +Arguments: + Variable Pointer to the Variable Header. Returns: - TRUE Variable header is valid. - FALSE Variable header is not valid. + + VARIABLE_HEADER* Pointer to next variable header. --*/ { - if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) { - return FALSE; + UINTN Value; + + if (!IsValidVariableHeader (Variable)) { + return NULL; } - return TRUE; + Value = (UINTN) GetVariableDataPtr (Variable); + Value += DataSizeOfVariable (Variable); + Value += GET_PAD_SIZE (DataSizeOfVariable (Variable)); + + // + // Be careful about pad size for alignment + // + return (VARIABLE_HEADER *) HEADER_ALIGN (Value); } -STATIC + VARIABLE_STORE_STATUS EFIAPI GetVariableStoreStatus ( @@ -215,7 +340,6 @@ Returns: } } -STATIC EFI_STATUS CompareWithValidVariable ( IN VARIABLE_HEADER *Variable, @@ -244,6 +368,8 @@ Returns: --*/ { + VOID *Point; + if (VariableName[0] == 0) { PtrTrack->CurrPtr = Variable; return EFI_SUCCESS; @@ -258,8 +384,9 @@ Returns: (((INT32 *) VendorGuid)[2] == ((INT32 *) &Variable->VendorGuid)[2]) && (((INT32 *) VendorGuid)[3] == ((INT32 *) &Variable->VendorGuid)[3]) ) { - ASSERT (NAMESIZE_OF_VARIABLE (Variable) != 0); - if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable), NAMESIZE_OF_VARIABLE (Variable))) { + ASSERT (NameSizeOfVariable (Variable) != 0); + Point = (VOID *) GetVariableNamePtr (Variable); + if (!CompareMem (VariableName, Point, NameSizeOfVariable (Variable))) { PtrTrack->CurrPtr = Variable; return EFI_SUCCESS; } @@ -269,11 +396,10 @@ Returns: return EFI_NOT_FOUND; } -STATIC EFI_STATUS EFIAPI FindVariable ( - IN EFI_PEI_SERVICES **PeiServices, + IN CONST EFI_PEI_SERVICES **PeiServices, IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack @@ -452,10 +578,10 @@ Returns: VARIABLE_POINTER_TRACK Variable; UINTN VarDataSize; EFI_STATUS Status; - EFI_PEI_SERVICES **PeiServices; + CONST EFI_PEI_SERVICES **PeiServices; PeiServices = GetPeiServicesTablePointer (); - if (VariableName == NULL || VariableGuid == NULL) { + if (VariableName == NULL || VariableGuid == NULL || DataSize == NULL) { return EFI_INVALID_PARAMETER; } // @@ -468,9 +594,16 @@ Returns: // // Get data size // - VarDataSize = DATASIZE_OF_VARIABLE (Variable.CurrPtr); + VarDataSize = DataSizeOfVariable (Variable.CurrPtr); if (*DataSize >= VarDataSize) { - (*PeiServices)->CopyMem (Data, GET_VARIABLE_DATA_PTR (Variable.CurrPtr), VarDataSize); + // + // PO-TKW: Address one checking in this place + // + if (Data == NULL) { + return EFI_INVALID_PARAMETER; + } + + (*PeiServices)->CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize); if (Attributes != NULL) { *Attributes = Variable.CurrPtr->Attributes; @@ -522,10 +655,10 @@ Returns: VARIABLE_POINTER_TRACK Variable; UINTN VarNameSize; EFI_STATUS Status; - EFI_PEI_SERVICES **PeiServices; + CONST EFI_PEI_SERVICES **PeiServices; PeiServices = GetPeiServicesTablePointer (); - if (VariableName == NULL) { + if (VariableName == NULL || VariableGuid == NULL || VariableNameSize == NULL) { return EFI_INVALID_PARAMETER; } @@ -544,11 +677,11 @@ Returns: while (!(Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL)) { if (IsValidVariableHeader (Variable.CurrPtr)) { if (Variable.CurrPtr->State == VAR_ADDED) { - ASSERT (NAMESIZE_OF_VARIABLE (Variable.CurrPtr) != 0); + ASSERT (NameSizeOfVariable (Variable.CurrPtr) != 0); - VarNameSize = (UINTN) NAMESIZE_OF_VARIABLE (Variable.CurrPtr); + VarNameSize = (UINTN) NameSizeOfVariable (Variable.CurrPtr); if (VarNameSize <= *VariableNameSize) { - (*PeiServices)->CopyMem (VariableName, GET_VARIABLE_NAME_PTR (Variable.CurrPtr), VarNameSize); + (*PeiServices)->CopyMem (VariableName, GetVariableNamePtr (Variable.CurrPtr), VarNameSize); (*PeiServices)->CopyMem (VariableGuid, &Variable.CurrPtr->VendorGuid, sizeof (EFI_GUID));