]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideLib.c
MdeModulePkg/PlatformDriOverrideDxe: Fix overflow condition check
[mirror_edk2.git] / MdeModulePkg / Universal / PlatformDriOverrideDxe / PlatDriOverrideLib.c
index 86c34be88d0f1338dfd5a1828ba593d3b2692569..bd2d04452f8bb87e7da2941fa146a39ea54d9bfa 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Implementation of the shared functions to do the platform driver vverride mapping.\r
 \r
-  Copyright (c) 2007 - 2015, 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
-\r
-  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
+  Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -751,7 +745,7 @@ InitOverridesMapping (
       //\r
       // Check buffer overflow.\r
       //\r
-      if ((OverrideItem->ControllerDevicePath == NULL) || (VariableIndex < (UINT8 *) ControllerDevicePath) || \r
+      if ((OverrideItem->ControllerDevicePath == NULL) || (VariableIndex < (UINT8 *) ControllerDevicePath) ||\r
           (VariableIndex > (UINT8 *) VariableBuffer + BufferSize)) {\r
         Corrupted = TRUE;\r
         break;\r
@@ -781,8 +775,8 @@ InitOverridesMapping (
         //\r
         // Check buffer overflow\r
         //\r
-        if ((DriverImageInfo->DriverImagePath == NULL) || (VariableIndex < (UINT8 *) DriverDevicePath) || \r
-            (VariableIndex < (UINT8 *) VariableBuffer + BufferSize)) {\r
+        if ((DriverImageInfo->DriverImagePath == NULL) || (VariableIndex < (UINT8 *) DriverDevicePath) ||\r
+            (VariableIndex > (UINT8 *) VariableBuffer + BufferSize)) {\r
           Corrupted = TRUE;\r
           break;\r
         }\r
@@ -1094,7 +1088,7 @@ SaveOverridesMapping (
     if (EFI_ERROR (Status)) {\r
       if (NumIndex > 0) {\r
         //\r
-        // Delete all PlatDriOver variables when full mapping can't be set.  \r
+        // Delete all PlatDriOver variables when full mapping can't be set.\r
         //\r
         DeleteOverridesVariables ();\r
       }\r
@@ -1112,7 +1106,7 @@ SaveOverridesMapping (
 \r
   @param  ImageHandle          The Image handle\r
   @param  BindingHandle        The BindingHandle of the found Driver Binding protocol.\r
-                               If Binding protocol is not found, it is set to NULL. \r
+                               If Binding protocol is not found, it is set to NULL.\r
 \r
   @return                      Pointer into the Binding Protocol interface\r
   @retval NULL                 The parameter is not valid or the binding protocol is not found.\r
@@ -1492,6 +1486,15 @@ GetDriverFromMapping (
                 DriverImageInfo->ImageHandle = ImageHandle;\r
               }\r
             } else {\r
+              //\r
+              // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an ImageHandle was created\r
+              // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be started right now.\r
+              // If the caller doesn't have the option to defer the execution of an image, we should\r
+              // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak.\r
+              //\r
+              if (Status == EFI_SECURITY_VIOLATION) {\r
+                gBS->UnloadImage (ImageHandle);\r
+              }\r
               DriverImageInfo->UnLoadable = TRUE;\r
               DriverImageInfo->ImageHandle = NULL;\r
             }\r
@@ -1551,8 +1554,8 @@ GetDriverFromMapping (
 \r
   @retval EFI_INVALID_PARAMETER    ControllerDevicePath or MappingDataBase is NULL.\r
   @retval EFI_NOT_FOUND            ControllerDevicePath is not found in MappingDataBase or\r
-                                   DriverImageDevicePath is not found in the found DriverImage Info list. \r
-  @retval EFI_SUCCESS              The controller's total override driver number and \r
+                                   DriverImageDevicePath is not found in the found DriverImage Info list.\r
+  @retval EFI_SUCCESS              The controller's total override driver number and\r
                                    input DriverImage's order number is correctly return.\r
 **/\r
 EFI_STATUS\r
@@ -1668,14 +1671,14 @@ CheckMapping (
                                    override driver image item\r
   @param  DriverImageDevicePath    The driver image device path need to be insert\r
   @param  MappingDataBase          Mapping database list entry pointer\r
-  @param  DriverImageNO            The inserted order number. If this number is taken, \r
+  @param  DriverImageNO            The inserted order number. If this number is taken,\r
                                    the larger available number will be used.\r
 \r
   @retval EFI_INVALID_PARAMETER    ControllerDevicePath is NULL, or DriverImageDevicePath is NULL\r
                                    or MappingDataBase is NULL\r
-  @retval EFI_ALREADY_STARTED      The input Controller to input DriverImage has been \r
+  @retval EFI_ALREADY_STARTED      The input Controller to input DriverImage has been\r
                                    recorded into the mapping database.\r
-  @retval EFI_SUCCESS              The Controller and DriverImage are inserted into \r
+  @retval EFI_SUCCESS              The Controller and DriverImage are inserted into\r
                                    the mapping database successfully.\r
 \r
 **/\r
@@ -1799,7 +1802,7 @@ InsertDriverImage (
 /**\r
   Delete a controller's override driver from the mapping database.\r
 \r
-  @param  ControllerDevicePath     The controller device path will be deleted \r
+  @param  ControllerDevicePath     The controller device path will be deleted\r
                                    when all drivers images on it are removed.\r
   @param  DriverImageDevicePath    The driver image device path will be delete.\r
                                    If NULL, all driver image will be delete.\r
@@ -1807,7 +1810,7 @@ InsertDriverImage (
 \r
   @retval EFI_INVALID_PARAMETER    ControllerDevicePath is NULL, or MappingDataBase is NULL\r
   @retval EFI_NOT_FOUND            ControllerDevicePath is not found in MappingDataBase or\r
-                                   DriverImageDevicePath is not found in the found DriverImage Info list. \r
+                                   DriverImageDevicePath is not found in the found DriverImage Info list.\r
   @retval EFI_SUCCESS              Delete the specified driver successfully.\r
 \r
 **/\r