Revision: 15359
http://sourceforge.net/p/edk2/code/15359
Author: vanjeff
Date: 2014-03-21 01:48:45 +0000 (Fri, 21 Mar 2014)
Log Message:
-----------
Sync patch r15357 from main trunk.
MdeModulePkg PCD: Fix PCD driver to return default data if size mismatch.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <[email protected]>
Revision Links:
--------------
http://sourceforge.net/p/edk2/code/15357
Modified Paths:
--------------
branches/UDK2010.SR1/MdeModulePkg/Universal/PCD/Dxe/Service.c
branches/UDK2010.SR1/MdeModulePkg/Universal/PCD/Pei/Service.c
Modified: branches/UDK2010.SR1/MdeModulePkg/Universal/PCD/Dxe/Service.c
===================================================================
--- branches/UDK2010.SR1/MdeModulePkg/Universal/PCD/Dxe/Service.c
2014-03-21 01:48:06 UTC (rev 15358)
+++ branches/UDK2010.SR1/MdeModulePkg/Universal/PCD/Dxe/Service.c
2014-03-21 01:48:45 UTC (rev 15359)
@@ -135,41 +135,30 @@
Name = (UINT16*)(StringTable + VariableHead->StringIndex);
if ((LocalTokenNumber & PCD_TYPE_ALL_SET) ==
(PCD_TYPE_HII|PCD_TYPE_STRING)) {
- //
- // If a HII type PCD's datum type is VOID*, the
DefaultValueOffset is the index of
- // string array in string table.
- //
+ //
+ // If a HII type PCD's datum type is VOID*, the DefaultValueOffset is
the index of
+ // string array in string table.
+ //
StringTableIdx = *(UINT16*)((UINT8 *) PcdDb +
VariableHead->DefaultValueOffset);
- VaraiableDefaultBuffer = (VOID *) (StringTable + StringTableIdx);
- Status = GetHiiVariable (Guid, Name, &Data, &DataSize);
- if (Status == EFI_SUCCESS) {
- if (GetSize == 0) {
- //
- // It is a pointer type. So get the MaxSize reserved for
- // this PCD entry.
- //
- GetPtrTypeSize (TmpTokenNumber, &GetSize);
- }
- //
- // If the operation is successful, we copy the data
- // to the default value buffer in the PCD Database.
- // So that we can free the Data allocated in GetHiiVariable.
- //
- CopyMem (VaraiableDefaultBuffer, Data + VariableHead->Offset,
GetSize);
- FreePool (Data);
- }
- RetPtr = (VOID *) VaraiableDefaultBuffer;
+ VaraiableDefaultBuffer = (UINT8 *) (StringTable + StringTableIdx);
} else {
VaraiableDefaultBuffer = (UINT8 *) PcdDb +
VariableHead->DefaultValueOffset;
-
- Status = GetHiiVariable (Guid, Name, &Data, &DataSize);
- if (Status == EFI_SUCCESS) {
+ }
+ Status = GetHiiVariable (Guid, Name, &Data, &DataSize);
+ if (Status == EFI_SUCCESS) {
+ if (DataSize >= (VariableHead->Offset + GetSize)) {
if (GetSize == 0) {
//
// It is a pointer type. So get the MaxSize reserved for
// this PCD entry.
//
GetPtrTypeSize (TmpTokenNumber, &GetSize);
+ if (GetSize > (DataSize - VariableHead->Offset)) {
+ //
+ // Use actual valid size.
+ //
+ GetSize = DataSize - VariableHead->Offset;
+ }
}
//
// If the operation is successful, we copy the data
@@ -177,10 +166,10 @@
// So that we can free the Data allocated in GetHiiVariable.
//
CopyMem (VaraiableDefaultBuffer, Data + VariableHead->Offset,
GetSize);
- FreePool (Data);
}
- RetPtr = (VOID *) VaraiableDefaultBuffer;
+ FreePool (Data);
}
+ RetPtr = (VOID *) VaraiableDefaultBuffer;
break;
case PCD_TYPE_STRING:
Modified: branches/UDK2010.SR1/MdeModulePkg/Universal/PCD/Pei/Service.c
===================================================================
--- branches/UDK2010.SR1/MdeModulePkg/Universal/PCD/Pei/Service.c
2014-03-21 01:48:06 UTC (rev 15358)
+++ branches/UDK2010.SR1/MdeModulePkg/Universal/PCD/Pei/Service.c
2014-03-21 01:48:45 UTC (rev 15359)
@@ -598,6 +598,7 @@
PEI_PCD_DATABASE *PeiPcdDb;
UINT32 LocalTokenNumber;
UINTN MaxSize;
+ UINT8 *VaraiableDefaultBuffer;
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
@@ -645,20 +646,37 @@
Guid = &(PeiPcdDb->Init.GuidTable[VariableHead->GuidTableIndex]);
Name = (UINT16*)&StringTable[VariableHead->StringIndex];
+ if ((LocalTokenNumber & PCD_TYPE_ALL_SET) ==
(PCD_TYPE_HII|PCD_TYPE_STRING)) {
+ //
+ // If a HII type PCD's datum type is VOID*, the DefaultValueOffset is
the index of
+ // string array in string table.
+ //
+ VaraiableDefaultBuffer = (UINT8 *) &StringTable[*(UINT16*)((UINT8*)
PeiPcdDb + VariableHead->DefaultValueOffset)];
+ } else {
+ VaraiableDefaultBuffer = (UINT8 *) PeiPcdDb +
VariableHead->DefaultValueOffset;
+ }
Status = GetHiiVariable (Guid, Name, &Data, &DataSize);
-
- if (Status == EFI_SUCCESS) {
- return (VOID *) ((UINT8 *) Data + VariableHead->Offset);
- } else {
+ if ((Status == EFI_SUCCESS) && (DataSize >= (VariableHead->Offset +
GetSize))) {
+ if (GetSize == 0) {
+ //
+ // It is a pointer type. So get the MaxSize reserved for
+ // this PCD entry.
+ //
+ GetPtrTypeSize (TokenNumber, &GetSize, PeiPcdDb);
+ if (GetSize > (DataSize - VariableHead->Offset)) {
+ //
+ // Use actual valid size.
+ //
+ GetSize = DataSize - VariableHead->Offset;
+ }
+ }
//
- // Return the default value specified by Platform Integrator
+ // If the operation is successful, we copy the data
+ // to the default value buffer in the PCD Database.
//
- if ((LocalTokenNumber & PCD_TYPE_ALL_SET) ==
(PCD_TYPE_HII|PCD_TYPE_STRING)) {
- return (VOID*)&StringTable[*(UINT16*)((UINT8*)PeiPcdDb +
VariableHead->DefaultValueOffset)];
- } else {
- return (VOID *) ((UINT8 *) PeiPcdDb +
VariableHead->DefaultValueOffset);
- }
+ CopyMem (VaraiableDefaultBuffer, (UINT8 *) Data +
VariableHead->Offset, GetSize);
}
+ return (VOID *) VaraiableDefaultBuffer;
}
case PCD_TYPE_DATA:
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits