]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/DxeServicesLib/DxeServicesLib.c
MdePkg DxeServicesLib: Handle potential NULL FvHandle
[mirror_edk2.git] / MdePkg / Library / DxeServicesLib / DxeServicesLib.c
index 2adf76fd8d22744297601f5b2c91966d52d2cefa..1827c9216fbc231c98b756b0bc66e7c7b13c7b58 100644 (file)
@@ -2,7 +2,7 @@
   MDE DXE Services Library provides functions that simplify the development of DXE Drivers.  \r
   These functions help access data from sections of FFS files or from file path.\r
 \r
-  Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
   (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -62,6 +62,12 @@ InternalImageHandleToFvHandle (
 \r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // The LoadedImage->DeviceHandle may be NULL.\r
+  // For example for DxeCore, there is LoadedImage protocol installed for it, but the\r
+  // LoadedImage->DeviceHandle could not be initialized before the FV2 (contain DxeCore)\r
+  // protocol is installed.\r
+  //\r
   return LoadedImage->DeviceHandle;\r
 \r
 }\r
@@ -84,7 +90,6 @@ InternalImageHandleToFvHandle (
   The data and size is returned by Buffer and Size. The caller is responsible to free the Buffer allocated \r
   by this function. This function can be only called at TPL_NOTIFY and below.\r
   \r
-  If FvHandle is NULL, then ASSERT ();\r
   If NameGuid is NULL, then ASSERT();\r
   If Buffer is NULL, then ASSERT();\r
   If Size is NULL, then ASSERT().\r
@@ -128,7 +133,12 @@ InternalGetSectionFromFv (
   ASSERT (Buffer != NULL);\r
   ASSERT (Size != NULL);\r
   \r
-  ASSERT (FvHandle != NULL);\r
+  if (FvHandle == NULL) {\r
+    //\r
+    // Return EFI_NOT_FOUND directly for NULL FvHandle.\r
+    //\r
+    return EFI_NOT_FOUND;\r
+  }\r
 \r
   Status = gBS->HandleProtocol (\r
                   FvHandle,\r