]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
Do not assert in HiiBlockToConfig function when an invalid format of ConfigRequest...
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / ConfigRouting.c
index 2f38b56e2bef9a733a306ab2ee3841b8b13a053d..30f602d30fe316aa2877106fa42a1990eba02a8c 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
 Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL.\r
 \r
-Copyright (c) 2007 - 2008, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2007 - 2011, 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -453,8 +453,9 @@ GetValueOfNumber (
   UINTN                    Index;\r
   CHAR16                   TemStr[2];\r
 \r
-  ASSERT (StringPtr != NULL && Number != NULL && Len != NULL);\r
-  ASSERT (*StringPtr != L'\0');\r
+  if (StringPtr == NULL || *StringPtr == L'\0' || Number == NULL || Len == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
 \r
   Buf = NULL;\r
 \r
@@ -860,6 +861,7 @@ ParseIfrData (
   EFI_STRING               NameStr;\r
   EFI_STRING               TempStr;\r
   UINTN                    LengthString;\r
+  BOOLEAN                  FirstOneOfOption;\r
 \r
   LengthString     = 0;\r
   Status           = EFI_SUCCESS;\r
@@ -869,6 +871,7 @@ ParseIfrData (
   BlockData        = NULL;\r
   DefaultData      = NULL;\r
   VarDefaultName   = 0;\r
+  FirstOneOfOption = FALSE;\r
 \r
   //\r
   // Go through the form package to parse OpCode one by one.\r
@@ -951,6 +954,7 @@ ParseIfrData (
       break;\r
 \r
     case EFI_IFR_FORM_OP:\r
+    case EFI_IFR_FORM_MAP_OP:\r
       //\r
       // No matched varstore is found and directly return.\r
       //\r
@@ -1022,6 +1026,59 @@ ParseIfrData (
       // Add Block Data into VarStorageData BlockEntry\r
       //\r
       InsertBlockData (&VarStorageData->BlockEntry, &BlockData);\r
+      \r
+      if (IfrOpHdr->OpCode == EFI_IFR_ONE_OF_OP) {\r
+        //\r
+        // Set this flag to TRUE for the first oneof option.\r
+        //\r
+        FirstOneOfOption = TRUE;\r
+      } else if (IfrOpHdr->OpCode == EFI_IFR_NUMERIC_OP) {\r
+        //\r
+        // Numeric minimum value will be used as default value when no default is specified. \r
+        //\r
+\r
+        //\r
+        // Set standard ID and Get DefaultName String ID\r
+        //\r
+        VarDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;\r
+        Status       = FindDefaultName (DefaultIdArray, VarDefaultId, &VarDefaultName);\r
+        if (EFI_ERROR (Status)) {\r
+          goto Done;\r
+        }\r
+        //\r
+        // Prepare new DefaultValue\r
+        //\r
+        DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));\r
+        if (DefaultData == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          goto Done;\r
+        }\r
+        DefaultData->OpCode      = IfrOpHdr->OpCode;\r
+        DefaultData->DefaultId   = VarDefaultId;\r
+        DefaultData->DefaultName = VarDefaultName;\r
+\r
+        switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) {\r
+        case EFI_IFR_NUMERIC_SIZE_1:\r
+          DefaultData->Value = (UINT64) IfrOneOf->data.u8.MinValue;\r
+          break;\r
+  \r
+        case EFI_IFR_NUMERIC_SIZE_2:\r
+          CopyMem (&DefaultData->Value, &IfrOneOf->data.u16.MinValue, sizeof (UINT16));\r
+          break;\r
+  \r
+        case EFI_IFR_NUMERIC_SIZE_4:\r
+          CopyMem (&DefaultData->Value, &IfrOneOf->data.u32.MinValue, sizeof (UINT32));\r
+          break;\r
+  \r
+        case EFI_IFR_NUMERIC_SIZE_8:\r
+          CopyMem (&DefaultData->Value, &IfrOneOf->data.u64.MinValue, sizeof (UINT64));\r
+          break;\r
+        }\r
+        //\r
+        // Add DefaultValue into current BlockData\r
+        //\r
+        InsertDefaultValue (BlockData, DefaultData);      \r
+      }\r
       break;\r
 \r
     case EFI_IFR_ORDERED_LIST_OP:\r
@@ -1098,7 +1155,7 @@ ParseIfrData (
       // Get Offset/Width by Question header and OneOf Flags\r
       //\r
       VarOffset = IfrCheckBox->Question.VarStoreInfo.VarOffset;\r
-      VarWidth  = sizeof (BOOLEAN);\r
+      VarWidth  = (UINT16) sizeof (BOOLEAN);\r
 \r
       //\r
       // Check whether this question is in requested block array.\r
@@ -1401,7 +1458,13 @@ ParseIfrData (
         break;\r
       }\r
 \r
-      if ((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT) == EFI_IFR_OPTION_DEFAULT) {\r
+      if (((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT) == EFI_IFR_OPTION_DEFAULT) ||\r
+          (BlockData->OpCode == EFI_IFR_ONE_OF_OP && FirstOneOfOption)) {\r
+        //\r
+        // This flag is used to specify whether this option is the first. Set it to FALSE for the following options. \r
+        // The first oneof option value will be used as default value when no default value is specified. \r
+        //\r
+        FirstOneOfOption = FALSE;\r
         //\r
         // Set standard ID to Manufacture ID and Get DefaultName String ID\r
         //\r
@@ -3041,7 +3104,7 @@ HiiBlockToConfig (
     // Get Offset\r
     //\r
     Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
-    if (Status == EFI_OUT_OF_RESOURCES) {\r
+    if (EFI_ERROR (Status)) {\r
       *Progress = ConfigRequest;\r
       goto Exit;\r
     }\r
@@ -3065,7 +3128,7 @@ HiiBlockToConfig (
     // Get Width\r
     //\r
     Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
-    if (Status == EFI_OUT_OF_RESOURCES) {\r
+    if (EFI_ERROR (Status)) {\r
       *Progress = ConfigRequest;\r
       goto Exit;\r
     }\r
@@ -3191,7 +3254,7 @@ Exit:
   @param  This                   A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r
                                  instance.\r
   @param  ConfigResp             A null-terminated Unicode string in <ConfigResp>\r
-                                 format. It can be ConfigAltResp format string.\r
+                                 format.\r
   @param  Block                  A possibly null array of bytes representing the\r
                                  current  block. Only bytes referenced in the\r
                                  ConfigResp string  in the block are modified. If\r
@@ -3223,6 +3286,10 @@ Exit:
                                  value pair. Block is left updated and\r
                                  Progress points at the '&' preceding the first\r
                                  non-<BlockName>.\r
+  @retval EFI_DEVICE_ERROR       Block not large enough. Progress undefined.\r
+  @retval EFI_NOT_FOUND          Target for the specified routing data was not found.\r
+                                 Progress points to the "G" in "GUID" of the errant\r
+                                 routing data.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -3244,13 +3311,14 @@ HiiConfigToBlock (
   UINTN                               Width;\r
   UINT8                               *Value;\r
   UINTN                               BufferSize;\r
+  UINTN                               MaxBlockSize;\r
 \r
   if (This == NULL || BlockSize == NULL || Progress == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (ConfigResp == NULL || Block == NULL) {\r
-    *Progress = ConfigResp;\r
+  *Progress = ConfigResp;\r
+  if (ConfigResp == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -3260,6 +3328,7 @@ HiiConfigToBlock (
   StringPtr  = ConfigResp;\r
   BufferSize = *BlockSize;\r
   Value      = NULL;\r
+  MaxBlockSize = 0;\r
 \r
   //\r
   // Jump <ConfigHdr>\r
@@ -3326,7 +3395,7 @@ HiiConfigToBlock (
     // Get Width\r
     //\r
     Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
-    if (Status == EFI_OUT_OF_RESOURCES) {\r
+    if (EFI_ERROR (Status)) {\r
       *Progress = ConfigResp;\r
       goto Exit;\r
     }\r
@@ -3365,13 +3434,12 @@ HiiConfigToBlock (
     //\r
     // Update the Block with configuration info\r
     //\r
-\r
-    if (Offset + Width > BufferSize) {\r
-      return EFI_DEVICE_ERROR;\r
+    if ((Block != NULL) && (Offset + Width <= BufferSize)) {\r
+      CopyMem (Block + Offset, Value, Width);\r
+    }\r
+    if (Offset + Width > MaxBlockSize) {\r
+      MaxBlockSize = Offset + Width;\r
     }\r
-\r
-    CopyMem (Block + Offset, Value, Width);\r
-    *BlockSize = Offset + Width - 1;\r
 \r
     FreePool (Value);\r
     Value = NULL;\r
@@ -3396,6 +3464,20 @@ HiiConfigToBlock (
   }\r
 \r
   *Progress = StringPtr + StrLen (StringPtr);\r
+  *BlockSize = MaxBlockSize - 1;\r
+\r
+  if (MaxBlockSize > BufferSize) {\r
+    *BlockSize = MaxBlockSize;\r
+    if (Block != NULL) {\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+  }\r
+\r
+  if (Block == NULL) {\r
+    *Progress = ConfigResp;\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 \r
 Exit:\r
@@ -3414,7 +3496,7 @@ Exit:
   @param  This                   A pointer to the EFI_HII_CONFIG_ROUTING_PROTOCOL\r
                                  instance.\r
   @param  Configuration          A null-terminated Unicode string in\r
-                                 <MultiConfigAltResp> format. It is <ConfigAltResp> format.\r
+                                 <MultiConfigAltResp> format.\r
   @param  Guid                   A pointer to the GUID value to search for in the\r
                                  routing portion of the ConfigResp string when\r
                                  retrieving  the requested data. If Guid is NULL,\r