]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Refine logic about validate boot option.
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 May 2012 05:04:13 +0000 (05:04 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 May 2012 05:04:13 +0000 (05:04 +0000)
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13362 6f19259b-4bc3-4df7-8a09-765794883524

IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c

index ada77d26ded416c8ad455a573f680bf5c29c7596..0a034cda96755f5f214a11164b1b4d4c8065f96d 100644 (file)
@@ -455,7 +455,7 @@ GetDevicePathSizeEx (
   bigger than MaxStringLen, return length 0 to indicate that this is an \r
   invalidate string.\r
 \r
-  This function returns the number of Unicode characters in the Null-terminated\r
+  This function returns the byte length of Unicode characters in the Null-terminated\r
   Unicode string specified by String. \r
 \r
   If String is NULL, then ASSERT().\r
@@ -479,13 +479,13 @@ StrSizeEx (
   ASSERT (String != NULL && MaxStringLen != 0);\r
   ASSERT (((UINTN) String & BIT0) == 0);\r
 \r
-  for (Length = 0; *String != L'\0' && MaxStringLen != Length; String++, Length++);\r
+  for (Length = 0; *String != L'\0' && MaxStringLen != Length; String++, Length+=2);\r
 \r
   if (*String != L'\0' && MaxStringLen == Length) {\r
     return 0;\r
   }\r
 \r
-  return (Length + 1) * sizeof (*String);\r
+  return Length + 2;\r
 }\r
 \r
 /**\r
@@ -507,9 +507,12 @@ ValidateOption (
   UINT16                    FilePathSize;\r
   UINT8                     *TempPtr;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *TempPath;\r
   UINTN                     TempSize;\r
 \r
+  if (VariableSize <= sizeof (UINT16) + sizeof (UINT32)) {\r
+    return FALSE;\r
+  }\r
+\r
   //\r
   // Skip the option attribute\r
   //\r
@@ -525,14 +528,14 @@ ValidateOption (
   //\r
   // Get the option's description string size\r
   //\r
-  TempSize = StrSizeEx ((CHAR16 *) TempPtr, VariableSize);\r
+  TempSize = StrSizeEx ((CHAR16 *) TempPtr, VariableSize - sizeof (UINT16) - sizeof (UINT32));\r
   TempPtr += TempSize;\r
 \r
   //\r
   // Get the option's device path\r
   //\r
   DevicePath =  (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;\r
-  TempPtr    += FilePathSize;\r
+  TempPtr   += FilePathSize;\r
 \r
   //\r
   // Validation boot option variable.\r
@@ -541,21 +544,11 @@ ValidateOption (
     return FALSE;\r
   }\r
 \r
-  if (TempSize + FilePathSize + sizeof (UINT16) + sizeof (UINT16) > VariableSize) {\r
+  if (TempSize + FilePathSize + sizeof (UINT16) + sizeof (UINT32) > VariableSize) {\r
     return FALSE;\r
   }\r
 \r
-  TempPath = DevicePath;\r
-  while (FilePathSize > 0) {\r
-    TempSize = GetDevicePathSizeEx (TempPath, FilePathSize);\r
-    if (TempSize == 0) {\r
-      return FALSE;\r
-    }\r
-    FilePathSize = (UINT16) (FilePathSize - TempSize);\r
-    TempPath    += TempSize;\r
-  }\r
-\r
-  return TRUE;\r
+  return GetDevicePathSizeEx (DevicePath, FilePathSize) != 0;\r
 }\r
 \r
 /**\r
@@ -608,13 +601,12 @@ BdsLibVariableToOption (
   UINT8                     *TempPtr;\r
   UINTN                     VariableSize;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *TempPath;\r
   BDS_COMMON_OPTION         *Option;\r
   VOID                      *LoadOptions;\r
   UINT32                    LoadOptionsSize;\r
   CHAR16                    *Description;\r
   UINT8                     NumOff;\r
-  UINTN                     TempSize;\r
+\r
   //\r
   // Read the variable. We will never free this data.\r
   //\r
@@ -659,11 +651,7 @@ BdsLibVariableToOption (
   //\r
   // Get the option's description string size\r
   //\r
-  TempSize = StrSizeEx ((CHAR16 *) TempPtr, VariableSize);\r
-  if (TempSize == 0) {\r
-    return NULL;\r
-  }\r
-  TempPtr += TempSize;\r
+  TempPtr += StrSize((CHAR16 *) TempPtr);\r
 \r
   //\r
   // Get the option's device path\r
@@ -671,26 +659,10 @@ BdsLibVariableToOption (
   DevicePath =  (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;\r
   TempPtr    += FilePathSize;\r
 \r
-  //\r
-  // Validation device path.\r
-  //\r
-  TempPath       = DevicePath;\r
-  while (FilePathSize > 0) {\r
-    TempSize = GetDevicePathSizeEx (TempPath, FilePathSize);\r
-    if (TempSize == 0) {\r
-      return NULL;\r
-    }\r
-    FilePathSize = (UINT16) (FilePathSize - TempSize);\r
-    TempPath    += TempSize;\r
-  }\r
-\r
   //\r
   // Get load opion data.\r
   //\r
   LoadOptions     = TempPtr;\r
-  if (VariableSize < (UINTN)(TempPtr - Variable)) {\r
-    return NULL;\r
-  }\r
   LoadOptionsSize = (UINT32) (VariableSize - (UINTN) (TempPtr - Variable));\r
 \r
   //\r