]> 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 d5ef60b7f5ed3eb223d96c60123df4b3bb319351..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
@@ -168,7 +168,7 @@ GetDevicePath (
   Converts the unicode character of the string from uppercase to lowercase.\r
   This is a internal function.\r
 \r
-  @param Str     String to be converted\r
+  @param ConfigString  String to be converted\r
 \r
 **/\r
 VOID\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
@@ -773,7 +774,7 @@ InsertBlockData (
 /**\r
   This function checks VarOffset and VarWidth is in the block range.\r
 \r
-  @param  BlockArray         The block array is to be checked. \r
+  @param  RequestBlockArray  The block array is to be checked. \r
   @param  VarOffset          Offset of var to the structure\r
   @param  VarWidth           Width of var.\r
   \r
@@ -831,7 +832,7 @@ EFI_STATUS
 EFIAPI\r
 ParseIfrData (\r
   IN     UINT8               *Package,\r
-  IN     UINT32              PackageLenth,\r
+  IN     UINT32              PackageLength,\r
   IN     EFI_STRING          ConfigHdr,\r
   IN     IFR_BLOCK_DATA      *RequestBlockArray,\r
   IN OUT IFR_VARSTORAGE_DATA *VarStorageData,\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
@@ -868,12 +870,14 @@ ParseIfrData (
   TempStr          = NULL;\r
   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
   //\r
   IfrOffset   = sizeof (EFI_HII_PACKAGE_HEADER);\r
-  while (IfrOffset < PackageLenth) {\r
+  while (IfrOffset < PackageLength) {\r
     IfrOpHdr  = (EFI_IFR_OP_HEADER *) (Package + IfrOffset);\r
 \r
     switch (IfrOpHdr->OpCode) {\r
@@ -950,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
@@ -1021,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
@@ -1042,32 +1100,15 @@ ParseIfrData (
       //\r
       IfrOrderedList = (EFI_IFR_ORDERED_LIST *) IfrOpHdr;\r
       if (IfrOrderedList->Question.VarStoreId != VarStorageData->VarStoreId) {\r
+        BlockData = NULL;\r
         break;\r
       }\r
-      \r
+\r
       //\r
       // Get Offset/Width by Question header and OneOf Flags\r
       //\r
       VarOffset = IfrOrderedList->Question.VarStoreInfo.VarOffset;\r
       VarWidth  = IfrOrderedList->MaxContainers;\r
-\r
-      //\r
-      // Check whether this question is in requested block array.\r
-      //\r
-      if (!BlockArrayCheck (RequestBlockArray, VarOffset, VarWidth)) {\r
-        //\r
-        // This question is not in the requested string. Skip it.\r
-        //\r
-        break;\r
-      }\r
-\r
-      //\r
-      // Check this var question is in the var storage \r
-      //\r
-      if ((VarOffset + VarWidth) > VarStorageData->Size) {\r
-        Status = EFI_INVALID_PARAMETER;\r
-        goto Done;\r
-      }\r
       \r
       //\r
       // Set Block Data\r
@@ -1083,11 +1124,6 @@ ParseIfrData (
       BlockData->OpCode     = IfrOpHdr->OpCode;\r
       BlockData->Scope      = IfrOpHdr->Scope;\r
       InitializeListHead (&BlockData->DefaultValueEntry);\r
-      \r
-      //\r
-      // Add Block Data into VarStorageData BlockEntry\r
-      //\r
-      InsertBlockData (&VarStorageData->BlockEntry, &BlockData);\r
       break;\r
 \r
     case EFI_IFR_CHECKBOX_OP:\r
@@ -1119,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
@@ -1384,17 +1420,51 @@ ParseIfrData (
           // Invalid ordered list option data type.\r
           //\r
           Status = EFI_INVALID_PARAMETER;\r
+          FreePool (BlockData);\r
           goto Done;\r
         }\r
+\r
         //\r
         // Calculate Ordered list QuestionId width.\r
         //\r
         BlockData->Width = (UINT16) (BlockData->Width * VarWidth);\r
+        //\r
+        // Check whether this question is in requested block array.\r
+        //\r
+        if (!BlockArrayCheck (RequestBlockArray, BlockData->Offset, BlockData->Width)) {\r
+          //\r
+          // This question is not in the requested string. Skip it.\r
+          //\r
+          FreePool (BlockData);\r
+          BlockData = NULL;\r
+          break;\r
+        }\r
+        //\r
+        // Check this var question is in the var storage \r
+        //\r
+        if ((BlockData->Offset + BlockData->Width) > VarStorageData->Size) {\r
+          Status = EFI_INVALID_PARAMETER;\r
+          FreePool (BlockData);\r
+          goto Done;\r
+        }\r
+        //\r
+        // Add Block Data into VarStorageData BlockEntry\r
+        //\r
+        InsertBlockData (&VarStorageData->BlockEntry, &BlockData);\r
+        //\r
+        // No default data for OrderedList.\r
+        //\r
         BlockData = NULL;\r
         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
@@ -3034,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
@@ -3058,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
@@ -3184,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
@@ -3216,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
@@ -3237,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
@@ -3253,6 +3328,7 @@ HiiConfigToBlock (
   StringPtr  = ConfigResp;\r
   BufferSize = *BlockSize;\r
   Value      = NULL;\r
+  MaxBlockSize = 0;\r
 \r
   //\r
   // Jump <ConfigHdr>\r
@@ -3319,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
@@ -3358,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
@@ -3389,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
@@ -3407,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