]> 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 0c8629c06fe290ef15706d6f1e9267ee268b8df5..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,15 +10,7 @@ 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
@@ -738,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
@@ -749,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
@@ -809,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
@@ -834,7 +838,7 @@ Returns:
     }\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  return EFI_NOT_FOUND;\r
 }\r
 \r
 //\r