]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/PCD/Dxe/Service.c
MdeModulePkg PCD: Fix PCD driver to return default data if size mismatch.
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Dxe / Service.c
index a9e1ca49a30f4a15355fc5f51dca3012289e2b26..4cbf6dd209ec6e72662e46311f96a019fcf8d63e 100644 (file)
@@ -1,7 +1,7 @@
 /** @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
@@ -457,25 +457,33 @@ GetWorker (
         // 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
-        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
-          // 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
-          GetPtrTypeSize (TmpTokenNumber, &GetSize);\r
+          CopyMem (VaraiableDefaultBuffer, Data + VariableHead->Offset, GetSize);\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