]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/GenericBdsLib/BdsMisc.c
Parameter checking in BdsLibMatchDevicePaths() is wrong. This bug was found because...
[mirror_edk2.git] / MdeModulePkg / Library / GenericBdsLib / BdsMisc.c
index 499d0f30b3a9fa9e464c3b5a8a9d41cc1ad7a7fd..8b3dcd783b8d60b63124719d7c859a69dea8c93d 100644 (file)
@@ -304,25 +304,27 @@ BdsLibRegisterNewOption (
         //\r
         // Got the option, so just return\r
         //\r
-        SafeFreePool (OptionPtr);\r
-        SafeFreePool (TempOptionPtr);\r
+        FreePool (OptionPtr);\r
+        FreePool (TempOptionPtr);\r
         return EFI_SUCCESS;\r
       } else {\r
         //\r
         // Option description changed, need update.\r
         //\r
         UpdateDescription = TRUE;\r
-        SafeFreePool (OptionPtr);\r
+        FreePool (OptionPtr);\r
         break;\r
       }\r
     }\r
 \r
-    SafeFreePool (OptionPtr);\r
+    FreePool (OptionPtr);\r
   }\r
 \r
   OptionSize          = sizeof (UINT32) + sizeof (UINT16) + StrSize (String);\r
   OptionSize          += GetDevicePathSize (DevicePath);\r
   OptionPtr           = AllocateZeroPool (OptionSize);\r
+  ASSERT (OptionPtr != NULL);\r
+  \r
   TempPtr             = OptionPtr;\r
   *(UINT32 *) TempPtr = LOAD_OPTION_ACTIVE;\r
   TempPtr             += sizeof (UINT32);\r
@@ -361,12 +363,14 @@ BdsLibRegisterNewOption (
   // Return if only need to update a changed description or fail to set option.\r
   //\r
   if (EFI_ERROR (Status) || UpdateDescription) {\r
-    SafeFreePool (OptionPtr);\r
-    SafeFreePool (TempOptionPtr);\r
+    FreePool (OptionPtr);\r
+    if (TempOptionPtr != NULL) {\r
+      FreePool (TempOptionPtr);\r
+    }\r
     return Status;\r
   }\r
 \r
-  SafeFreePool (OptionPtr);\r
+  FreePool (OptionPtr);\r
 \r
   //\r
   // Update the option order variable\r
@@ -384,7 +388,9 @@ BdsLibRegisterNewOption (
                     sizeof (UINT16),\r
                     &BootOrderEntry\r
                     );\r
-    SafeFreePool (TempOptionPtr);\r
+    if (TempOptionPtr != NULL) {\r
+      FreePool (TempOptionPtr);\r
+    }\r
     return Status;\r
   }\r
 \r
@@ -393,6 +399,8 @@ BdsLibRegisterNewOption (
   //\r
   OrderItemNum = (TempOptionSize / sizeof (UINT16)) + 1 ;\r
   OptionOrderPtr = AllocateZeroPool ( OrderItemNum * sizeof (UINT16));\r
+  ASSERT (OptionOrderPtr!= NULL);\r
+  \r
   CopyMem (OptionOrderPtr, TempOptionPtr, (OrderItemNum - 1) * sizeof (UINT16));\r
 \r
   OptionOrderPtr[Index] = RegisterOptionNumber;\r
@@ -404,8 +412,8 @@ BdsLibRegisterNewOption (
                   OrderItemNum * sizeof (UINT16),\r
                   OptionOrderPtr\r
                   );\r
-  SafeFreePool (TempOptionPtr);\r
-  SafeFreePool (OptionOrderPtr);\r
+  FreePool (TempOptionPtr);\r
+  FreePool (OptionOrderPtr);\r
 \r
   return Status;\r
 }\r
@@ -525,12 +533,12 @@ BdsLibVariableToOption (
   //\r
   if ((Option->Attribute & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE) {\r
     InsertTailList (BdsCommonOptionList, &Option->Link);\r
-    SafeFreePool (Variable);\r
+    FreePool (Variable);\r
     return Option;\r
   }\r
 \r
-  SafeFreePool (Variable);\r
-  SafeFreePool (Option);\r
+  FreePool (Variable);\r
+  FreePool (Option);\r
   return NULL;\r
 \r
 }\r
@@ -591,7 +599,7 @@ BdsLibBuildOptionFromVar (
 \r
   }\r
 \r
-  SafeFreePool (OptionOrder);\r
+  FreePool (OptionOrder);\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -716,9 +724,11 @@ BdsLibDelPartMatchInstance (
       //\r
       TempNewDevicePath = NewDevicePath;\r
       NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance);\r
-      SafeFreePool(TempNewDevicePath);\r
+      if (TempNewDevicePath != NULL) {\r
+        FreePool(TempNewDevicePath);\r
+      }\r
     }\r
-    SafeFreePool(Instance);\r
+    FreePool(Instance);\r
     Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);\r
     InstanceSize  -= END_DEVICE_PATH_LENGTH;\r
   }\r
@@ -750,7 +760,7 @@ BdsLibMatchDevicePaths (
   EFI_DEVICE_PATH_PROTOCOL  *DevicePathInst;\r
   UINTN                     Size;\r
 \r
-  if (Multi != NULL || Single  != NULL) {\r
+  if (Multi == NULL || Single  == NULL) {\r
     return FALSE;\r
   }\r
 \r
@@ -766,11 +776,11 @@ BdsLibMatchDevicePaths (
     // return success\r
     //\r
     if (CompareMem (Single, DevicePathInst, Size) == 0) {\r
-      SafeFreePool (DevicePathInst);\r
+      FreePool (DevicePathInst);\r
       return TRUE;\r
     }\r
 \r
-    SafeFreePool (DevicePathInst);\r
+    FreePool (DevicePathInst);\r
     DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
   }\r
 \r
@@ -952,8 +962,8 @@ SetupResetReminder (
         IfrLibCreatePopUp (2, &Key, StringBuffer1, StringBuffer2);\r
       } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
 \r
-      SafeFreePool (StringBuffer1);\r
-      SafeFreePool (StringBuffer2);\r
+      FreePool (StringBuffer1);\r
+      FreePool (StringBuffer2);\r
       //\r
       // If the user hits the YES Response key, reset\r
       //\r
@@ -1014,7 +1024,7 @@ BdsLibGetImageHeader (
                      &Root\r
                      );\r
   if (EFI_ERROR (Status)) {\r
-    Root = NULL;
+    Root = NULL;\r
     goto Done;\r
   }\r
 \r
@@ -1043,13 +1053,14 @@ BdsLibGetImageHeader (
       break;\r
     }\r
     if (Status != EFI_BUFFER_TOO_SMALL) {\r
+      FreePool (Info);\r
       goto Done;\r
     }\r
-    SafeFreePool (Info);\r
+    FreePool (Info);\r
   } while (TRUE);\r
 \r
   FileSize = Info->FileSize;\r
-  SafeFreePool (Info);\r
+  FreePool (Info);\r
 \r
   //\r
   // Read dos header\r