]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg DxeServicesLib: Handle potential NULL FvHandle
authorStar Zeng <star.zeng@intel.com>
Fri, 5 May 2017 08:11:57 +0000 (16:11 +0800)
committerStar Zeng <star.zeng@intel.com>
Mon, 8 May 2017 00:57:03 +0000 (08:57 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=514

The FvHandle input to InternalGetSectionFromFv() may be NULL,
then ASSERT will appear. It is because the LoadedImage->DeviceHandle
returned from InternalImageHandleToFvHandle() may be NULL.
For example for DxeCore, there is LoadedImage protocol installed
for it, but the LoadedImage->DeviceHandle could not be initialized
before the FV2 (contain DxeCore) protocol is installed.

This patch is to update InternalGetSectionFromFv() to return
EFI_NOT_FOUND directly for NULL FvHandle.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
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