From 2b21a9713ce974c14f26dfb5d3496372e04b501b Mon Sep 17 00:00:00 2001 From: qwang12 Date: Thu, 6 Jul 2006 13:34:25 +0000 Subject: Fixed a bug when input a invalid token number (not ZERO nor a valid token number) PcdLib should ASSERT. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@802 6f19259b-4bc3-4df7-8a09-765794883524 --- EdkModulePkg/Universal/PCD/Dxe/Pcd.c | 32 +++++++++++++----------- EdkModulePkg/Universal/PCD/Dxe/Service.c | 42 +++++++++++++++++--------------- EdkModulePkg/Universal/PCD/Dxe/Service.h | 16 ++++++------ EdkModulePkg/Universal/PCD/Pei/Pcd.c | 3 +++ 4 files changed, 52 insertions(+), 41 deletions(-) (limited to 'EdkModulePkg/Universal/PCD') diff --git a/EdkModulePkg/Universal/PCD/Dxe/Pcd.c b/EdkModulePkg/Universal/PCD/Dxe/Pcd.c index b78752df29..115b1ac938 100644 --- a/EdkModulePkg/Universal/PCD/Dxe/Pcd.c +++ b/EdkModulePkg/Universal/PCD/Dxe/Pcd.c @@ -499,12 +499,18 @@ DxePcdGetNextToken ( IN OUT UINTN *TokenNumber ) { - UINTN ExTokenNumber; - + EFI_STATUS Status; + + Status = EFI_NOT_FOUND; // // Scan the local token space // if (Guid == NULL) { + if (((*TokenNumber > PEI_NEX_TOKEN_NUMBER) && (*TokenNumber < PEI_LOCAL_TOKEN_NUMBER)) || + ((*TokenNumber > (PEI_LOCAL_TOKEN_NUMBER + DXE_NEX_TOKEN_NUMBER)))) { + return EFI_NOT_FOUND; + } + (*TokenNumber)++; if (*TokenNumber > PEI_NEX_TOKEN_NUMBER && *TokenNumber <= PEI_LOCAL_TOKEN_NUMBER) { @@ -525,10 +531,9 @@ DxePcdGetNextToken ( } if (!PEI_EXMAP_TABLE_EMPTY) { - ExTokenNumber = *TokenNumber; - ExTokenNumber = ExGetNextTokeNumber ( + Status = ExGetNextTokeNumber ( Guid, - ExTokenNumber, + TokenNumber, mPcdDatabase->PeiDb.Init.GuidTable, sizeof(mPcdDatabase->PeiDb.Init.GuidTable), mPcdDatabase->PeiDb.Init.ExMapTable, @@ -536,13 +541,14 @@ DxePcdGetNextToken ( ); } - if ((ExTokenNumber == PCD_INVALID_TOKEN_NUMBER) && - !DXE_EXMAP_TABLE_EMPTY - ) { - ExTokenNumber = *TokenNumber; - ExTokenNumber = ExGetNextTokeNumber ( + if (Status == EFI_SUCCESS) { + return Status; + } + + if (!DXE_EXMAP_TABLE_EMPTY) { + Status = ExGetNextTokeNumber ( Guid, - ExTokenNumber, + TokenNumber, mPcdDatabase->DxeDb.Init.GuidTable, sizeof(mPcdDatabase->DxeDb.Init.GuidTable), mPcdDatabase->DxeDb.Init.ExMapTable, @@ -550,9 +556,7 @@ DxePcdGetNextToken ( ); } - *TokenNumber = ExTokenNumber; - - return EFI_SUCCESS; + return Status; } diff --git a/EdkModulePkg/Universal/PCD/Dxe/Service.c b/EdkModulePkg/Universal/PCD/Dxe/Service.c index adbbe5fc5a..613d8c84d1 100644 --- a/EdkModulePkg/Universal/PCD/Dxe/Service.c +++ b/EdkModulePkg/Universal/PCD/Dxe/Service.c @@ -109,7 +109,7 @@ GetWorker ( Name = &(StringTable[VariableHead->StringIndex]); VaraiableDefaultBuffer = (UINT8 *) PcdDb + VariableHead->DefaultValueOffset; - Status = GetHiiVariable (Guid, Name, (VOID*)&Data, &DataSize); + Status = GetHiiVariable (Guid, Name, &Data, &DataSize); if (Status == EFI_SUCCESS) { if (GetSize == 0) { // @@ -252,14 +252,14 @@ DxeUnRegisterCallBackWorker ( -UINTN +EFI_STATUS ExGetNextTokeNumber ( - IN CONST EFI_GUID *Guid, - IN UINTN TokenNumber, - IN EFI_GUID *GuidTable, - IN UINTN SizeOfGuidTable, - IN DYNAMICEX_MAPPING *ExMapTable, - IN UINTN SizeOfExMapTable + IN CONST EFI_GUID *Guid, + IN OUT UINTN *TokenNumber, + IN EFI_GUID *GuidTable, + IN UINTN SizeOfGuidTable, + IN DYNAMICEX_MAPPING *ExMapTable, + IN UINTN SizeOfExMapTable ) { EFI_GUID *MatchGuid; @@ -269,7 +269,7 @@ ExGetNextTokeNumber ( MatchGuid = ScanGuid (GuidTable, SizeOfGuidTable, Guid); if (MatchGuid == NULL) { - return PCD_INVALID_TOKEN_NUMBER; + return EFI_NOT_FOUND; } Found = FALSE; @@ -282,35 +282,39 @@ ExGetNextTokeNumber ( } if (Found) { - if (TokenNumber == PCD_INVALID_TOKEN_NUMBER) { - return ExMapTable[Idx].ExTokenNumber; + if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) { + *TokenNumber = ExMapTable[Idx].ExTokenNumber; + return EFI_SUCCESS; } for ( ; Idx < SizeOfExMapTable; Idx++) { - if (ExMapTable[Idx].ExTokenNumber == TokenNumber) { + if (ExMapTable[Idx].ExTokenNumber == *TokenNumber) { Idx++; if (Idx == SizeOfExMapTable) { // // Exceed the length of ExMap Table // - return PCD_INVALID_TOKEN_NUMBER; + *TokenNumber = PCD_INVALID_TOKEN_NUMBER; + return EFI_SUCCESS; } else if (ExMapTable[Idx].ExGuidIndex == GuidTableIdx) { // // Found the next match // - return ExMapTable[Idx].ExTokenNumber; + *TokenNumber = ExMapTable[Idx].ExTokenNumber; + return EFI_SUCCESS; } else { // // Guid has been changed. It is the next Token Space Guid. // We should flag no more TokenNumber. // - return PCD_INVALID_TOKEN_NUMBER; + *TokenNumber = PCD_INVALID_TOKEN_NUMBER; + return EFI_SUCCESS; } } } } - return PCD_INVALID_TOKEN_NUMBER; + return EFI_NOT_FOUND; } @@ -375,13 +379,13 @@ EFI_STATUS GetHiiVariable ( IN EFI_GUID *VariableGuid, IN UINT16 *VariableName, - OUT VOID **VariableData, + OUT UINT8 **VariableData, OUT UINTN *VariableSize ) { UINTN Size; EFI_STATUS Status; - VOID *Buffer; + UINT8 *Buffer; Size = 0; Buffer = NULL; @@ -395,7 +399,7 @@ GetHiiVariable ( ); if (Status == EFI_BUFFER_TOO_SMALL) { - Buffer = AllocatePool (Size); + Buffer = (UINT8 *) AllocatePool (Size); ASSERT (Buffer != NULL); diff --git a/EdkModulePkg/Universal/PCD/Dxe/Service.h b/EdkModulePkg/Universal/PCD/Dxe/Service.h index ff90fa5479..271d8b32c4 100644 --- a/EdkModulePkg/Universal/PCD/Dxe/Service.h +++ b/EdkModulePkg/Universal/PCD/Dxe/Service.h @@ -397,7 +397,7 @@ EFI_STATUS GetHiiVariable ( IN EFI_GUID *VariableGuid, IN UINT16 *VariableName, - OUT VOID **VariableData, + OUT UINT8 **VariableData, OUT UINTN *VariableSize ) ; @@ -441,14 +441,14 @@ GetExPcdTokenNumber ( -UINTN +EFI_STATUS ExGetNextTokeNumber ( - IN CONST EFI_GUID *Guid, - IN UINTN TokenNumber, - IN EFI_GUID *GuidTable, - IN UINTN SizeOfGuidTable, - IN DYNAMICEX_MAPPING *ExMapTable, - IN UINTN SizeOfExMapTable + IN CONST EFI_GUID *Guid, + IN OUT UINTN *TokenNumber, + IN EFI_GUID *GuidTable, + IN UINTN SizeOfGuidTable, + IN DYNAMICEX_MAPPING *ExMapTable, + IN UINTN SizeOfExMapTable ) ; diff --git a/EdkModulePkg/Universal/PCD/Pei/Pcd.c b/EdkModulePkg/Universal/PCD/Pei/Pcd.c index 6d90671852..4ae4b27ef4 100644 --- a/EdkModulePkg/Universal/PCD/Pei/Pcd.c +++ b/EdkModulePkg/Universal/PCD/Pei/Pcd.c @@ -480,6 +480,9 @@ PeiPcdGetNextToken ( BOOLEAN Found; if (Guid == NULL) { + if (*TokenNumber > PEI_NEX_TOKEN_NUMBER) { + return EFI_NOT_FOUND; + } (*TokenNumber)++; if (*TokenNumber > PEI_NEX_TOKEN_NUMBER) { *TokenNumber = PCD_INVALID_TOKEN_NUMBER; -- cgit v1.2.3