]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/PCD/Dxe/Service.c
Adds ASSERT check in DxePcd driver when error status of read DynamicHii PCD is not...
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Dxe / Service.c
index 8a550d38e03e532e92c82a2853284299ec848a87..6eaadd6cceef24b8e381c6a7a7a90e7d8e18584d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
     Help functions used by PCD DXE driver.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, 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
@@ -55,7 +55,7 @@ GetWorker (
   EFI_STATUS          Status;\r
   UINT32              LocalTokenNumber;\r
   UINT32              Offset;\r
-  UINT16              StringTableIdx;      \r
+  STRING_HEAD         StringTableIdx;      \r
   BOOLEAN             IsPeiDb;\r
 \r
   //\r
@@ -139,7 +139,7 @@ GetWorker (
                // If a HII type PCD's datum type is VOID*, the DefaultValueOffset is the index of \r
                // string array in string table.\r
                //\r
-        StringTableIdx = *(UINT16*)((UINT8 *) PcdDb + VariableHead->DefaultValueOffset);   \r
+        StringTableIdx = *(STRING_HEAD*)((UINT8 *) PcdDb + VariableHead->DefaultValueOffset);   \r
         VaraiableDefaultBuffer = (VOID *) (StringTable + StringTableIdx);     \r
         Status = GetHiiVariable (Guid, Name, &Data, &DataSize);\r
         if (Status == EFI_SUCCESS) {\r
@@ -150,6 +150,11 @@ GetWorker (
             //\r
             GetPtrTypeSize (TmpTokenNumber, &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
@@ -166,25 +171,20 @@ GetWorker (
             //\r
             GetPtrTypeSize (TmpTokenNumber, &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
-        //\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
-        // If the operation is not successful, \r
-        // Return 1) either the default value specified by Platform Integrator \r
-        //        2) Or the value Set by a PCD set operation.\r
-        //\r
         RetPtr = (VOID *) VaraiableDefaultBuffer;\r
       }\r
       break;\r
 \r
     case PCD_TYPE_STRING:\r
-      StringTableIdx = *(UINT16*)((UINT8 *) PcdDb + Offset);\r
+      StringTableIdx = *(STRING_HEAD*)((UINT8 *) PcdDb + Offset);\r
       RetPtr = (VOID *) (StringTable + StringTableIdx);\r
       break;\r
 \r
@@ -535,6 +535,12 @@ GetHiiVariable (
     ASSERT (Status == EFI_SUCCESS);\r
     *VariableData = Buffer;\r
     *VariableSize = Size;\r
+  } else {\r
+    //\r
+    // Use Default Data only when variable is not found. \r
+    // For other error status, correct data can't be got, and trig ASSERT().\r
+    //\r
+    ASSERT (Status == EFI_NOT_FOUND);\r
   }\r
 \r
   return Status;\r
@@ -741,7 +747,12 @@ SetWorker (
   ASSERT (TokenNumber + 1 < PCD_TOTAL_TOKEN_NUMBER + 1);\r
 \r
   if (PtrType) {\r
-    if (*Size > DxePcdGetSize (TokenNumber + 1)) {\r
+    //\r
+    // Get MaxSize first, then check new size with max buffer size.\r
+    //\r
+    GetPtrTypeSize (TokenNumber, &MaxSize);\r
+    if (*Size > MaxSize) {\r
+      *Size = MaxSize;\r
       return EFI_INVALID_PARAMETER;\r
     }\r
   } else {\r
@@ -810,7 +821,7 @@ SetWorker (
     \r
     case PCD_TYPE_STRING:\r
       if (SetPtrTypeSize (TmpTokenNumber, Size)) {\r
-        CopyMem (StringTable + *((UINT16 *)InternalData), Data, *Size);\r
+        CopyMem (StringTable + *((STRING_HEAD *)InternalData), Data, *Size);\r
         Status = EFI_SUCCESS;\r
       } else {\r
         Status = EFI_INVALID_PARAMETER;\r
@@ -842,7 +853,7 @@ SetWorker (
       if (EFI_NOT_FOUND == Status) {\r
         if ((LocalTokenNumber & PCD_TYPE_ALL_SET) == (PCD_TYPE_HII|PCD_TYPE_STRING))  {\r
           CopyMem (\r
-            StringTable + *(UINT16 *)(PcdDb + VariableHead->DefaultValueOffset),\r
+            StringTable + *(STRING_HEAD *)(PcdDb + VariableHead->DefaultValueOffset),\r
             Data,\r
             *Size\r
             );\r