]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Bds: Check variable name even *if* OptionNumber is NULL
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 10 Oct 2017 08:57:38 +0000 (16:57 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Thu, 12 Oct 2017 02:00:48 +0000 (10:00 +0800)
Current implementation skips to check whether the last four
characters are digits when the OptionNumber is NULL.
Even worse, it may incorrectly return FALSE when OptionNumber is
NULL.

The patch fixes it to always check the variable name even
OptionNumber is NULL.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c

index b0a35058d02bfb42e180058cdd5b3e7121dc8325..32918caf324ccdc98893149ccd9be4fc5320c7fe 100644 (file)
@@ -785,6 +785,8 @@ EfiBootManagerIsValidLoadOptionVariableName (
   UINTN                             VariableNameLen;\r
   UINTN                             Index;\r
   UINTN                             Uint;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LocalOptionType;\r
+  UINT16                            LocalOptionNumber;\r
 \r
   if (VariableName == NULL) {\r
     return FALSE;\r
@@ -792,39 +794,52 @@ EfiBootManagerIsValidLoadOptionVariableName (
 \r
   VariableNameLen = StrLen (VariableName);\r
 \r
+  //\r
+  // Return FALSE when the variable name length is too small.\r
+  //\r
   if (VariableNameLen <= 4) {\r
     return FALSE;\r
   }\r
 \r
-  for (Index = 0; Index < ARRAY_SIZE (mBmLoadOptionName); Index++) {\r
-    if ((VariableNameLen - 4 == StrLen (mBmLoadOptionName[Index])) &&\r
-        (StrnCmp (VariableName, mBmLoadOptionName[Index], VariableNameLen - 4) == 0)\r
+  //\r
+  // Return FALSE when the variable name doesn't start with Driver/SysPrep/Boot/PlatformRecovery.\r
+  //\r
+  for (LocalOptionType = 0; LocalOptionType < ARRAY_SIZE (mBmLoadOptionName); LocalOptionType++) {\r
+    if ((VariableNameLen - 4 == StrLen (mBmLoadOptionName[LocalOptionType])) &&\r
+        (StrnCmp (VariableName, mBmLoadOptionName[LocalOptionType], VariableNameLen - 4) == 0)\r
         ) {\r
       break;\r
     }\r
   }\r
+  if (LocalOptionType == ARRAY_SIZE (mBmLoadOptionName)) {\r
+    return FALSE;\r
+  }\r
 \r
-  if (Index == ARRAY_SIZE (mBmLoadOptionName)) {\r
+  //\r
+  // Return FALSE when the last four characters are not hex digits.\r
+  //\r
+  LocalOptionNumber = 0;\r
+  for (Index = VariableNameLen - 4; Index < VariableNameLen; Index++) {\r
+    Uint = BmCharToUint (VariableName[Index]);\r
+    if (Uint == -1) {\r
+      break;\r
+    } else {\r
+      LocalOptionNumber = (UINT16) Uint + LocalOptionNumber * 0x10;\r
+    }\r
+  }\r
+  if (Index != VariableNameLen) {\r
     return FALSE;\r
   }\r
 \r
   if (OptionType != NULL) {\r
-    *OptionType = (EFI_BOOT_MANAGER_LOAD_OPTION_TYPE) Index;\r
+    *OptionType = LocalOptionType;\r
   }\r
 \r
   if (OptionNumber != NULL) {\r
-    *OptionNumber = 0;\r
-    for (Index = VariableNameLen - 4; Index < VariableNameLen; Index++) {\r
-      Uint = BmCharToUint (VariableName[Index]);\r
-      if (Uint == -1) {\r
-        break;\r
-      } else {\r
-        *OptionNumber = (UINT16) Uint + *OptionNumber * 0x10;\r
-      }\r
-    }\r
+    *OptionNumber = LocalOptionNumber;\r
   }\r
 \r
-  return (BOOLEAN) (Index == VariableNameLen);\r
+  return TRUE;\r
 }\r
 \r
 /**\r