From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 6D55621A0483B for ; Thu, 20 Apr 2017 01:07:08 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Apr 2017 01:07:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,224,1488873600"; d="scan'208";a="91690943" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga005.fm.intel.com with ESMTP; 20 Apr 2017 01:07:04 -0700 Received: from fmsmsx114.amr.corp.intel.com (10.18.116.8) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 20 Apr 2017 01:07:02 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by FMSMSX114.amr.corp.intel.com (10.18.116.8) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 20 Apr 2017 01:07:01 -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; Thu, 20 Apr 2017 16:07:00 +0800 From: "Zhang, Chao B" To: "Wu, Jiaxin" , "edk2-devel@lists.01.org" CC: "Ye, Ting" , "Fu, Siyuan" Thread-Topic: [PATCH v2] NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource Thread-Index: AQHSt0FpiPFEytt3bU2Z7DFyIaKfFKHN65XA Date: Thu, 20 Apr 2017 08:06:59 +0000 Message-ID: References: <1492409462-3224-1-git-send-email-jiaxin.wu@intel.com> In-Reply-To: <1492409462-3224-1-git-send-email-jiaxin.wu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v2] NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource 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: Thu, 20 Apr 2017 08:07:08 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Chao Zhang -----Original Message----- From: Wu, Jiaxin=20 Sent: Monday, April 17, 2017 2:11 PM To: edk2-devel@lists.01.org Cc: Zhang, Chao B ; Ye, Ting ; F= u, Siyuan ; Wu, Jiaxin Subject: [PATCH v2] NetworkPkg/TlsAuthConfigDxe: Close and free the file re= lated resource v2: * Define one new internal function to clean the file content. TlsAuthConfigDxe open file by FileExplorerLib. It need to close file handle= r and free file related resource in some cases. * User enrolls Cert by escape the Config page. * The Cert is not X509 type. * User chooses another file after he selected a file. Cc: Zhang Chao B Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin --- NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c | 49 +++++++++++++--------= ---- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c b/NetworkPkg/T= lsAuthConfigDxe/TlsAuthConfigImpl.c index 81f7e7d..faefc72 100644 --- a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c +++ b/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c @@ -294,11 +294,11 @@ ON_EXIT: } =20 /** Delete one entry from cert database. =20 - @param[in] PrivateData Module's private data. + @param[in] Private Module's private data. @param[in] VariableName The variable name of the database. @param[in] VendorGuid A unique identifier for the vendor. @param[in] LabelNumber Label number to insert opcodes. @param[in] FormId Form ID of current page. @param[in] QuestionIdBase Base question id of the cert list. @@ -475,22 +475,27 @@ ON_EXIT: ); } =20 =20 /** - Close an open file handle. + Clean the file related resource. =20 - @param[in] FileHandle The file handle to close. + @param[in] Private Module's private data. =20 **/ VOID -CloseFile ( - IN EFI_FILE_HANDLE FileHandle +CleanFileContext ( + IN TLS_AUTH_CONFIG_PRIVATE_DATA *Private ) { - if (FileHandle !=3D NULL) { - FileHandle->Close (FileHandle); + if (Private->FileContext->FHandle !=3D NULL) { + Private->FileContext->FHandle->Close (Private->FileContext->FHandle); + Private->FileContext->FHandle =3D NULL; + if (Private->FileContext->FileName!=3D NULL){ + FreePool(Private->FileContext->FileName); + Private->FileContext->FileName =3D NULL; + } } } =20 /** Read file content into BufferPtr, the size of the allocate buffer @@ -87= 1,18 +876,11 @@ EnrollX509toVariable ( if (EFI_ERROR (Status)) { goto ON_EXIT; } =20 ON_EXIT: - - CloseFile (Private->FileContext->FHandle); - if (Private->FileContext->FileName !=3D NULL) { - FreePool(Private->FileContext->FileName); - Private->FileContext->FileName =3D NULL; - } - - Private->FileContext->FHandle =3D NULL; + CleanFileContext (Private); =20 if (Private->CertGuid !=3D NULL) { FreePool (Private->CertGuid); Private->CertGuid =3D NULL; } @@ -1559,11 +1557,12 @@ TlsAuthConfigAccessCallback ( } =20 HiiGetBrowserData (&gTlsAuthConfigGuid, mTlsAuthConfigStorageName, Buffe= rSize, (UINT8 *) IfrNvData); =20 if ((Action !=3D EFI_BROWSER_ACTION_CHANGED) && - (Action !=3D EFI_BROWSER_ACTION_CHANGING)) { + (Action !=3D EFI_BROWSER_ACTION_CHANGING) &&=20 + (Action !=3D EFI_BROWSER_ACTION_FORM_CLOSE)) { Status =3D EFI_UNSUPPORTED; goto EXIT; } =20 if (Action =3D=3D EFI_BROWSER_ACTION_CHANGING) { @@ -1590,34 +1589,34 @@= TlsAuthConfigAccessCallback ( // Refresh selected file. // CleanUpPage (LabelId, Private); break; case KEY_TLS_AUTH_CONFIG_ENROLL_CERT_FROM_FILE: + // + // If the file is already opened, clean the file related resource fi= rst.=20 + // + CleanFileContext (Private); + =20 ChooseFile( NULL, NULL, UpdateCAFromFile, &File); break; =20 case KEY_TLS_AUTH_CONFIG_VALUE_SAVE_AND_EXIT: Status =3D EnrollCertDatabase (Private, EFI_TLS_CA_CERTIFICATE_VARIA= BLE); if (EFI_ERROR (Status)) { + CleanFileContext (Private); + CreatePopUp ( EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"ERROR: Enroll Cert Failure!", NULL ); } break; =20 case KEY_TLS_AUTH_CONFIG_VALUE_NO_SAVE_AND_EXIT: - if (Private->FileContext->FHandle !=3D NULL) { - CloseFile (Private->FileContext->FHandle); - Private->FileContext->FHandle =3D NULL; - if (Private->FileContext->FileName!=3D NULL){ - FreePool(Private->FileContext->FileName); - Private->FileContext->FileName =3D NULL; - } - } + CleanFileContext (Private); =20 if (Private->CertGuid!=3D NULL) { FreePool (Private->CertGuid); Private->CertGuid =3D NULL; } @@ -1665,10 +1664,12 @@ TlsAuthConfigAccessCallback ( *ActionRequest =3D EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; break; default: break; } + } else if (Action =3D=3D EFI_BROWSER_ACTION_FORM_CLOSE) { + CleanFileContext (Private); } =20 EXIT: =20 if (!EFI_ERROR (Status)) { -- 1.9.5.msysgit.1