]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Universal/UserInterface/HiiDataBase/Dxe/Forms.c
Fix the issue that HiiGetForms does not return correct BufferLength
[mirror_edk2.git] / EdkModulePkg / Universal / UserInterface / HiiDataBase / Dxe / Forms.c
index 2c625fe86e2008a2b3cf52f36b840e67ffaab575..b7b02a85f8919a7d606372fdfdf69dc2d9cf8367 100644 (file)
@@ -1,6 +1,7 @@
-/*++\r
-\r
-Copyright (c) 2006, Intel Corporation                                                         \r
+/**@file\r
+  This file contains the form processing code to the HII database.\r
+  \r
+Copyright (c) 2006 - 2007 Intel Corporation. <BR>\r
 All rights reserved. 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
@@ -9,19 +10,12 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
 \r
-Module Name:\r
-\r
-  Forms.c\r
-\r
-Abstract:\r
-\r
-  This file contains the form processing code to the HII database.\r
-\r
---*/\r
+**/\r
 \r
 \r
 #include "HiiDatabase.h"\r
 \r
+STATIC\r
 CHAR16*\r
 Ascii2Unicode (\r
   OUT CHAR16         *UnicodeStr,\r
@@ -54,6 +48,7 @@ Ascii2Unicode (
   }\r
 }\r
 \r
+STATIC\r
 CHAR8*\r
 Unicode2Ascii (\r
   OUT CHAR8          *AsciiStr,\r
@@ -86,6 +81,7 @@ Unicode2Ascii (
   }\r
 }\r
 \r
+STATIC\r
 VOID\r
 ExtractDevicePathData (\r
   IN     EFI_HII_DATA_TABLE   *DataTable,\r
@@ -129,6 +125,7 @@ Returns:
   *ExportBufferPtr  = ExportBuffer;\r
 }\r
 \r
+STATIC\r
 VOID\r
 ExtractVariableData (\r
   IN OUT EFI_HII_DATA_TABLE   *DataTable,\r
@@ -205,6 +202,7 @@ Returns:
                         &gEfiFormCallbackProtocolGuid,\r
                         (VOID *) &FormCallback\r
                         );\r
+        ASSERT_EFI_ERROR (Status);\r
       }\r
       //\r
       // Since we have a "Setup" variable that wasn't specified by a variable op-code\r
@@ -240,6 +238,7 @@ Returns:
                                  &TempValue,\r
                                  ExportBuffer\r
                                  );\r
+        ASSERT_EFI_ERROR (Status);\r
       } else {\r
         Status = gRT->GetVariable (\r
                         (CHAR16 *) SETUP_MAP_NAME,\r
@@ -248,6 +247,7 @@ Returns:
                         &TempValue,\r
                         ExportBuffer\r
                         );\r
+        ASSERT_EFI_ERROR (Status);\r
       }\r
 \r
       ExportBuffer = (UINT8 *) (UINTN) (((UINTN) ExportBuffer) + TempValue);\r
@@ -306,6 +306,7 @@ Returns:
                                  &TempValue,\r
                                  ExportBuffer\r
                                  );\r
+        ASSERT_EFI_ERROR (Status);\r
       } else {\r
         Status = gRT->GetVariable (\r
                         String,\r
@@ -314,6 +315,7 @@ Returns:
                         &TempValue,\r
                         ExportBuffer\r
                         );\r
+        ASSERT_EFI_ERROR (Status);\r
       }\r
 \r
       ExportBuffer = (UINT8 *) (UINTN) (((UINTN) ExportBuffer) + TempValue);\r
@@ -367,7 +369,6 @@ Returns:
   UINT8                     *ExportBuffer;\r
   EFI_HII_EXPORT_TABLE      *ExportTable;\r
   EFI_HII_DATA_TABLE        *DataTable;\r
-  BOOLEAN                   InsufficientSize;\r
   BOOLEAN                   VariableExist;\r
   UINT16                    NumberOfHiiDataTables;\r
   UINTN                     SizeNeeded;\r
@@ -386,7 +387,6 @@ Returns:
   FormPack              = NULL;\r
   RawData               = NULL;\r
   PackageInstance       = NULL;\r
-  InsufficientSize      = FALSE;\r
   NumberOfHiiDataTables = 0;\r
   VariableSize          = 0;\r
   TempValue             = 0;\r
@@ -731,6 +731,7 @@ Returns:
   EFI_IFR_FORM              *Form;\r
   EFI_IFR_OP_HEADER         *Location;\r
   UINT16                    *BufferLength = (UINT16 *) BufferLengthTemp;\r
+  UINTN                     FormLength;\r
 \r
   if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -742,6 +743,8 @@ Returns:
 \r
   PackageInstance = NULL;\r
 \r
+  FormLength      = 0;\r
+\r
   //\r
   // Check numeric value against the head of the database\r
   //\r
@@ -802,19 +805,27 @@ Returns:
         // If we found a Form Op-code and it is of the correct Id, copy it and return\r
         //\r
         if (Form->FormId == FormId) {\r
-          if (Location->Length > *BufferLength || Buffer == NULL) {\r
-            *BufferLength = Location->Length;\r
-            return EFI_BUFFER_TOO_SMALL;\r
-          } else {\r
-            for (; Location->OpCode != EFI_IFR_END_FORM_OP;) {\r
-              CopyMem (Buffer, Location, Location->Length);\r
-              Buffer    = Buffer + Location->Length;\r
-              Location  = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
-            }\r
+          //\r
+          // Calculate the total size of form\r
+          //\r
+          for (FormLength = 0; Location->OpCode != EFI_IFR_END_FORM_OP; ) {\r
+            FormLength += Location->Length;\r
+            Location    = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
+          }\r
+          FormLength += Location->Length;\r
+          Location    = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
 \r
-            CopyMem (Buffer, Location, Location->Length);\r
-            return EFI_SUCCESS;\r
+          if ((Buffer == NULL) || (FormLength > *BufferLength)) {\r
+            *BufferLengthTemp = FormLength;\r
+            return EFI_BUFFER_TOO_SMALL;\r
           }\r
+          \r
+          //\r
+          // Rewind to start offset of the found Form\r
+          //\r
+          Location   = (EFI_IFR_OP_HEADER *) ((CHAR8 *)Location - FormLength);\r
+          CopyMem (Buffer, Location, FormLength);\r
+          return EFI_SUCCESS;\r
         }\r
 \r
       default:\r
@@ -827,7 +838,7 @@ Returns:
     }\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  return EFI_NOT_FOUND;\r
 }\r
 \r
 //\r
@@ -1409,6 +1420,8 @@ Returns:
   TempBufferSize += PackageInstance->IfrSize + PackageInstance->StringSize;\r
 \r
   TempBuffer      = AllocateZeroPool (TempBufferSize);\r
+  ASSERT (TempBuffer != NULL);\r
+\r
   OrigTempBuffer  = TempBuffer;\r
 \r
   //\r