diff options
author | Jiaxin Wu <jiaxin.wu@intel.com> | 2017-04-10 10:30:38 +0800 |
---|---|---|
committer | Jiaxin Wu <jiaxin.wu@intel.com> | 2017-04-21 13:05:27 +0800 |
commit | 8ca417688363da941b329ce134e074971e864c34 (patch) | |
tree | 51ed1a030485915f4d3fe1c9b4a3260cedb1af24 /NetworkPkg | |
parent | 8cdd559be622f7a35731b7f973d8b82d1c9e303e (diff) | |
download | edk2-8ca417688363da941b329ce134e074971e864c34.tar.gz |
NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource
v2:
* Define one new internal function to clean the file content.
TlsAuthConfigDxe open file by FileExplorerLib. It need to close
file handler 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 <chao.b.zhang@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Chao Zhang<chao.b.zhang@intel.com>
Diffstat (limited to 'NetworkPkg')
-rw-r--r-- | NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c b/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c index 81f7e7d0f4..faefc72d0e 100644 --- a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c +++ b/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c @@ -296,7 +296,7 @@ ON_EXIT: /**
Delete one entry from cert database.
- @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.
@@ -477,18 +477,23 @@ ON_EXIT: /**
- Close an open file handle.
+ Clean the file related resource.
- @param[in] FileHandle The file handle to close.
+ @param[in] Private Module's private data.
**/
VOID
-CloseFile (
- IN EFI_FILE_HANDLE FileHandle
+CleanFileContext (
+ IN TLS_AUTH_CONFIG_PRIVATE_DATA *Private
)
{
- if (FileHandle != NULL) {
- FileHandle->Close (FileHandle);
+ if (Private->FileContext->FHandle != NULL) {
+ Private->FileContext->FHandle->Close (Private->FileContext->FHandle);
+ Private->FileContext->FHandle = NULL;
+ if (Private->FileContext->FileName!= NULL){
+ FreePool(Private->FileContext->FileName);
+ Private->FileContext->FileName = NULL;
+ }
}
}
@@ -873,14 +878,7 @@ EnrollX509toVariable ( }
ON_EXIT:
-
- CloseFile (Private->FileContext->FHandle);
- if (Private->FileContext->FileName != NULL) {
- FreePool(Private->FileContext->FileName);
- Private->FileContext->FileName = NULL;
- }
-
- Private->FileContext->FHandle = NULL;
+ CleanFileContext (Private);
if (Private->CertGuid != NULL) {
FreePool (Private->CertGuid);
@@ -1561,7 +1559,8 @@ TlsAuthConfigAccessCallback ( HiiGetBrowserData (&gTlsAuthConfigGuid, mTlsAuthConfigStorageName, BufferSize, (UINT8 *) IfrNvData);
if ((Action != EFI_BROWSER_ACTION_CHANGED) &&
- (Action != EFI_BROWSER_ACTION_CHANGING)) {
+ (Action != EFI_BROWSER_ACTION_CHANGING) &&
+ (Action != EFI_BROWSER_ACTION_FORM_CLOSE)) {
Status = EFI_UNSUPPORTED;
goto EXIT;
}
@@ -1592,12 +1591,19 @@ TlsAuthConfigAccessCallback ( CleanUpPage (LabelId, Private);
break;
case KEY_TLS_AUTH_CONFIG_ENROLL_CERT_FROM_FILE:
+ //
+ // If the file is already opened, clean the file related resource first.
+ //
+ CleanFileContext (Private);
+
ChooseFile( NULL, NULL, UpdateCAFromFile, &File);
break;
case KEY_TLS_AUTH_CONFIG_VALUE_SAVE_AND_EXIT:
Status = EnrollCertDatabase (Private, EFI_TLS_CA_CERTIFICATE_VARIABLE);
if (EFI_ERROR (Status)) {
+ CleanFileContext (Private);
+
CreatePopUp (
EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
&Key,
@@ -1608,14 +1614,7 @@ TlsAuthConfigAccessCallback ( break;
case KEY_TLS_AUTH_CONFIG_VALUE_NO_SAVE_AND_EXIT:
- if (Private->FileContext->FHandle != NULL) {
- CloseFile (Private->FileContext->FHandle);
- Private->FileContext->FHandle = NULL;
- if (Private->FileContext->FileName!= NULL){
- FreePool(Private->FileContext->FileName);
- Private->FileContext->FileName = NULL;
- }
- }
+ CleanFileContext (Private);
if (Private->CertGuid!= NULL) {
FreePool (Private->CertGuid);
@@ -1667,6 +1666,8 @@ TlsAuthConfigAccessCallback ( default:
break;
}
+ } else if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {
+ CleanFileContext (Private);
}
EXIT:
|