]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg PCD: Fix PCD driver to return default data if size mismatch.
authorStar Zeng <star.zeng@intel.com>
Fri, 21 Mar 2014 01:16:07 +0000 (01:16 +0000)
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 21 Mar 2014 01:16:07 +0000 (01:16 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15357 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/PCD/Dxe/Service.c
MdeModulePkg/Universal/PCD/Pei/Service.c

index a9e1ca49a30f4a15355fc5f51dca3012289e2b26..4cbf6dd209ec6e72662e46311f96a019fcf8d63e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
     Help functions used by PCD DXE driver.\r
 \r
 /** @file\r
     Help functions used by PCD DXE driver.\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
 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
@@ -457,25 +457,33 @@ GetWorker (
         // string array in string table.\r
         //\r
         StringTableIdx = *(STRING_HEAD*)((UINT8 *) PcdDb + VariableHead->DefaultValueOffset);   \r
         // string array in string table.\r
         //\r
         StringTableIdx = *(STRING_HEAD*)((UINT8 *) PcdDb + VariableHead->DefaultValueOffset);   \r
-        VaraiableDefaultBuffer = (VOID *) (StringTable + StringTableIdx);     \r
+        VaraiableDefaultBuffer = (UINT8 *) (StringTable + StringTableIdx);     \r
       } else {\r
         VaraiableDefaultBuffer = (UINT8 *) PcdDb + VariableHead->DefaultValueOffset;\r
       }\r
       Status = GetHiiVariable (Guid, Name, &Data, &DataSize);\r
       if (Status == EFI_SUCCESS) {\r
       } else {\r
         VaraiableDefaultBuffer = (UINT8 *) PcdDb + VariableHead->DefaultValueOffset;\r
       }\r
       Status = GetHiiVariable (Guid, Name, &Data, &DataSize);\r
       if (Status == EFI_SUCCESS) {\r
-        if (GetSize == 0) {\r
+        if (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 (TmpTokenNumber, &GetSize);\r
+            if (GetSize > (DataSize - VariableHead->Offset)) {\r
+              //\r
+              // Use actual valid size.\r
+              //\r
+              GetSize = DataSize - VariableHead->Offset;\r
+            }\r
+          }\r
           //\r
           //\r
-          // It is a pointer type. So get the MaxSize reserved for\r
-          // this PCD entry.\r
+          // If the operation is successful, we copy the data\r
+          // to the default value buffer in the PCD Database.\r
+          // So that we can free the Data allocated in GetHiiVariable.\r
           //\r
           //\r
-          GetPtrTypeSize (TmpTokenNumber, &GetSize);\r
+          CopyMem (VaraiableDefaultBuffer, Data + VariableHead->Offset, GetSize);\r
         }\r
         }\r
-        //\r
-        // If the operation is successful, we copy the data\r
-        // to the default value buffer in the PCD Database.\r
-        // So that we can free the Data allocated in GetHiiVariable.\r
-        //\r
-        CopyMem (VaraiableDefaultBuffer, Data + VariableHead->Offset, GetSize);\r
         FreePool (Data);\r
       }\r
       RetPtr = (VOID *) VaraiableDefaultBuffer;\r
         FreePool (Data);\r
       }\r
       RetPtr = (VOID *) VaraiableDefaultBuffer;\r
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
   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
 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
   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
 \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
       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
         //\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
         //\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
+        //\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
       }\r
+      return (VOID *) VaraiableDefaultBuffer;\r
     }\r
 \r
     case PCD_TYPE_DATA:\r
     }\r
 \r
     case PCD_TYPE_DATA:\r