]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/PCD/Pei/Service.c
MdeModulePkg PCD: Fix PCD driver to return default data if size mismatch.
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Pei / Service.c
index 4fb8b4a6878012b840a17d3fc41da4670a2c96c3..af40db8319c39489ef65cd1717838ef17cad5de4 100644 (file)
@@ -2,7 +2,7 @@
   The driver internal functions are implmented here.\r
   They build Pei PCD database, and provide access service to PCD database.\r
 \r
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -947,6 +947,7 @@ GetWorker (
   PEI_PCD_DATABASE    *PeiPcdDb;\r
   UINT32              LocalTokenNumber;\r
   UINT32              LocalTokenCount;\r
+  UINT8               *VaraiableDefaultBuffer;\r
 \r
   //\r
   // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.\r
@@ -986,20 +987,37 @@ GetWorker (
       Guid = (EFI_GUID *) ((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset) + VariableHead->GuidTableIndex;\r
       Name = (UINT16*)&StringTable[VariableHead->StringIndex];\r
 \r
-      Status = GetHiiVariable (Guid, Name, &Data, &DataSize);\r
-\r
-      if (Status == EFI_SUCCESS) {\r
-        return (VOID *) ((UINT8 *) Data + VariableHead->Offset);\r
-      } else {\r
+      if ((LocalTokenNumber & PCD_TYPE_ALL_SET) == (PCD_TYPE_HII|PCD_TYPE_STRING)) {\r
         //\r
-        // Return the default value specified by Platform Integrator \r
+        // If a HII type PCD's datum type is VOID*, the DefaultValueOffset is the index of \r
+        // string array in string table.\r
         //\r
-        if ((LocalTokenNumber & PCD_TYPE_ALL_SET) == (PCD_TYPE_HII|PCD_TYPE_STRING)) {\r
-          return (VOID*)&StringTable[*(STRING_HEAD*)((UINT8*)PeiPcdDb + VariableHead->DefaultValueOffset)];\r
-        } else {\r
-          return (VOID *) ((UINT8 *) PeiPcdDb + VariableHead->DefaultValueOffset);\r
+        VaraiableDefaultBuffer = (UINT8 *) &StringTable[*(STRING_HEAD*)((UINT8*) PeiPcdDb + VariableHead->DefaultValueOffset)];   \r
+      } else {\r
+        VaraiableDefaultBuffer = (UINT8 *) PeiPcdDb + VariableHead->DefaultValueOffset;\r
+      }\r
+      Status = GetHiiVariable (Guid, Name, &Data, &DataSize);\r
+      if ((Status == EFI_SUCCESS) && (DataSize >= (VariableHead->Offset + GetSize))) {\r
+        if (GetSize == 0) {\r
+          //\r
+          // It is a pointer type. So get the MaxSize reserved for\r
+          // this PCD entry.\r
+          //\r
+          GetPtrTypeSize (TokenNumber, &GetSize, PeiPcdDb);\r
+          if (GetSize > (DataSize - VariableHead->Offset)) {\r
+            //\r
+            // Use actual valid size.\r
+            //\r
+            GetSize = DataSize - VariableHead->Offset;\r
+          }\r
         }\r
+        //\r
+        // If the operation is successful, we copy the data\r
+        // to the default value buffer in the PCD Database.\r
+        //\r
+        CopyMem (VaraiableDefaultBuffer, (UINT8 *) Data + VariableHead->Offset, GetSize);\r
       }\r
+      return (VOID *) VaraiableDefaultBuffer;\r
     }\r
 \r
     case PCD_TYPE_DATA:\r