From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 7A45621A070BA for ; Fri, 5 May 2017 02:10:33 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP; 05 May 2017 02:10:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,291,1491289200"; d="scan'208";a="97601107" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga005.fm.intel.com with ESMTP; 05 May 2017 02:10:33 -0700 Received: from FMSMSX110.amr.corp.intel.com (10.18.116.10) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 5 May 2017 02:10:32 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx110.amr.corp.intel.com (10.18.116.10) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 5 May 2017 02:10:32 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.246]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.117]) with mapi id 14.03.0319.002; Fri, 5 May 2017 17:10:30 +0800 From: "Gao, Liming" To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: "Kinney, Michael D" , Michael Turner Thread-Topic: [PATCH] MdePkg DxeServicesLib: Handle potential NULL FvHandle Thread-Index: AQHSxXijsTbdba1sJkOCO+QSGgnd2qHlZrVw Date: Fri, 5 May 2017 09:10:29 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14D72A993@shsmsx102.ccr.corp.intel.com> References: <1493972489-55348-1-git-send-email-star.zeng@intel.com> In-Reply-To: <1493972489-55348-1-git-send-email-star.zeng@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [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: , X-List-Received-Date: Fri, 05 May 2017 09:10:33 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao >-----Original Message----- >From: Zeng, Star >Sent: Friday, May 05, 2017 4:21 PM >To: edk2-devel@lists.01.org >Cc: Zeng, Star ; Gao, Liming ; >Kinney, Michael D ; Michael Turner > >Subject: [PATCH] MdePkg DxeServicesLib: Handle potential NULL FvHandle > >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 >--- > MdePkg/Library/DxeServicesLib/DxeServicesLib.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > >diff --git a/MdePkg/Library/DxeServicesLib/DxeServicesLib.c >b/MdePkg/Library/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 developme= nt >of DXE Drivers. > These functions help access data from sections of FFS files or from fil= e path. > >- 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 B= SD >License >@@ -62,6 +62,12 @@ InternalImageHandleToFvHandle ( > > ASSERT_EFI_ERROR (Status); > >+ // >+ // 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 >(contain DxeCore) >+ // protocol is installed. >+ // > return LoadedImage->DeviceHandle; > > } >@@ -84,7 +90,6 @@ InternalImageHandleToFvHandle ( > The data and size is returned by Buffer and Size. The caller is respons= ible to >free the Buffer allocated > by this function. This function can be only called at TPL_NOTIFY and be= low. > >- 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); > >- ASSERT (FvHandle !=3D NULL); >+ if (FvHandle =3D=3D NULL) { >+ // >+ // Return EFI_NOT_FOUND directly for NULL FvHandle. >+ // >+ return EFI_NOT_FOUND; >+ } > > Status =3D gBS->HandleProtocol ( > FvHandle, >-- >2.7.0.windows.1