]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
Fix a bug in GetOptionalStringByIndex() that doesn't handle the case when Index ...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / FrontPage.c
index 39d2e235e3d935a771088a1a5e930e68b0ec717b..62ba39484306455382592a3039213a8f2d3e6a2c 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   FrontPage routines to handle the callbacks and browser calls\r
 \r
-Copyright (c) 2004 - 2009, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2004 - 2010, 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
@@ -173,6 +173,13 @@ FrontPageCallback (
   CHAR8                         *PlatformSupportedLanguages;\r
   CHAR8                         *BestLanguage;\r
 \r
+  if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {\r
+    //\r
+    // Do nothing for UEFI OPEN/CLOSE Action\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
   if ((Value == NULL) || (ActionRequest == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -436,7 +443,7 @@ InitializeFrontPage (
 \r
     if (FirstFlag) {\r
       StringBuffer = HiiGetString (HiiHandle, PRINTABLE_LANGUAGE_NAME_STRING_ID, Lang);\r
-      ASSERT_EFI_ERROR (StringBuffer != NULL);\r
+      ASSERT (StringBuffer != NULL);\r
 \r
       //\r
       // Save the string Id for each language\r
@@ -656,51 +663,27 @@ GetOptionalStringByIndex (
   OUT     CHAR16                  **String\r
   )\r
 {\r
-  UINT8          StrNum;\r
-  UINTN          CurrentStrLen;\r
-  CHAR8*         CharInStr;\r
-  EFI_STATUS     Status;\r
+  UINTN          StrSize;\r
 \r
-  StrNum        = 0;\r
-  Status        = EFI_NOT_FOUND;\r
-  CharInStr     = OptionalStrStart;\r
+  if (Index == 0) {\r
+    *String = AllocateZeroPool (sizeof (CHAR16));\r
+    return EFI_SUCCESS;\r
+  }\r
 \r
-  if (Index != 1) {\r
-    CurrentStrLen = 0;\r
-    //\r
-    // look for the two consecutive zeros, check the string limit by the way.\r
-    //\r
-    while (*CharInStr != 0 || *(CharInStr+1) != 0) { \r
-      if (*CharInStr == 0) {\r
-        StrNum += 1;\r
-        CharInStr++;\r
-      }\r
-  \r
-      if (StrNum == Index) {\r
-        Status = EFI_SUCCESS;\r
-        break;\r
-      }\r
-  \r
-      CurrentStrLen = AsciiStrLen(CharInStr);\r
-  \r
-      //\r
-      // forward the pointer\r
-      //\r
-      OptionalStrStart = CharInStr;\r
-      CharInStr += CurrentStrLen;\r
-    }\r
-  \r
-    if (EFI_ERROR (Status)) {\r
-      *String = GetStringById (STRING_TOKEN (STR_MISSING_STRING));\r
-      return Status;\r
-    }\r
+  StrSize = 0;\r
+  do {\r
+    Index--;\r
+    OptionalStrStart += StrSize;\r
+    StrSize           = AsciiStrSize (OptionalStrStart);\r
+  } while (OptionalStrStart[StrSize] != 0 && Index != 0);\r
+\r
+  if (Index != 0) {\r
+    *String = GetStringById (STRING_TOKEN (STR_MISSING_STRING));\r
   } else {\r
-    CurrentStrLen = AsciiStrLen(CharInStr);\r
+    *String = AllocatePool (StrSize * sizeof (CHAR16));\r
+    AsciiStrToUnicodeStr (OptionalStrStart, *String);\r
   }\r
 \r
-  *String = AllocatePool((CurrentStrLen + 1)*sizeof(CHAR16));\r
-  AsciiStrToUnicodeStr(OptionalStrStart, *String);\r
-\r
   return EFI_SUCCESS;\r
 }\r
 \r