From nobody Mon Apr 29 17:30:19 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1493972498185435.80513894188505; Fri, 5 May 2017 01:21:38 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DD28921A134BC; Fri, 5 May 2017 01:21:35 -0700 (PDT) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C8A1521A134AE for ; Fri, 5 May 2017 01:21:34 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP; 05 May 2017 01:21:34 -0700 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.9.20]) by fmsmga006.fm.intel.com with ESMTP; 05 May 2017 01:21:32 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,291,1491289200"; d="scan'208";a="97984367" From: Star Zeng To: edk2-devel@lists.01.org Date: Fri, 5 May 2017 16:21:29 +0800 Message-Id: <1493972489-55348-1-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 Subject: [edk2] [PATCH] MdePkg DxeServicesLib: Handle potential NULL FvHandle X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Michael Turner , Liming Gao , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D514 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 Cc: Michael Kinney Cc: Michael Turner Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng Reviewed-by: Liming Gao --- MdePkg/Library/DxeServicesLib/DxeServicesLib.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/MdePkg/Library/DxeServicesLib/DxeServicesLib.c b/MdePkg/Librar= y/DxeServicesLib/DxeServicesLib.c index 2adf76fd8d22..1827c9216fbc 100644 --- a/MdePkg/Library/DxeServicesLib/DxeServicesLib.c +++ b/MdePkg/Library/DxeServicesLib/DxeServicesLib.c @@ -2,7 +2,7 @@ MDE DXE Services Library provides functions that simplify the developmen= t of DXE Drivers. =20 These functions help access data from sections of FFS files or from file= path. =20 - Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License @@ -62,6 +62,12 @@ InternalImageHandleToFvHandle ( =20 ASSERT_EFI_ERROR (Status); =20 + // + // The LoadedImage->DeviceHandle 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 (co= ntain DxeCore) + // protocol is installed. + // return LoadedImage->DeviceHandle; =20 } @@ -84,7 +90,6 @@ InternalImageHandleToFvHandle ( The data and size is returned by Buffer and Size. The caller is responsi= ble to free the Buffer allocated=20 by this function. This function can be only called at TPL_NOTIFY and bel= ow. =20 - If FvHandle is NULL, then ASSERT (); If NameGuid is NULL, then ASSERT(); If Buffer is NULL, then ASSERT(); If Size is NULL, then ASSERT(). @@ -128,7 +133,12 @@ InternalGetSectionFromFv ( ASSERT (Buffer !=3D NULL); ASSERT (Size !=3D NULL); =20 - ASSERT (FvHandle !=3D NULL); + if (FvHandle =3D=3D NULL) { + // + // Return EFI_NOT_FOUND directly for NULL FvHandle. + // + return EFI_NOT_FOUND; + } =20 Status =3D gBS->HandleProtocol ( FvHandle, --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel