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>
(cherry picked from commit 8ca4176883)
This commit is contained in:
Jiaxin Wu
2017-04-10 10:30:38 +08:00
parent d1ffb4e436
commit ca740d75d6

View File

@ -296,7 +296,7 @@ ON_EXIT:
/** /**
Delete one entry from cert database. 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] VariableName The variable name of the database.
@param[in] VendorGuid A unique identifier for the vendor. @param[in] VendorGuid A unique identifier for the vendor.
@param[in] LabelNumber Label number to insert opcodes. @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 VOID
CloseFile ( CleanFileContext (
IN EFI_FILE_HANDLE FileHandle IN TLS_AUTH_CONFIG_PRIVATE_DATA *Private
) )
{ {
if (FileHandle != NULL) { if (Private->FileContext->FHandle != NULL) {
FileHandle->Close (FileHandle); 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: ON_EXIT:
CleanFileContext (Private);
CloseFile (Private->FileContext->FHandle);
if (Private->FileContext->FileName != NULL) {
FreePool(Private->FileContext->FileName);
Private->FileContext->FileName = NULL;
}
Private->FileContext->FHandle = NULL;
if (Private->CertGuid != NULL) { if (Private->CertGuid != NULL) {
FreePool (Private->CertGuid); FreePool (Private->CertGuid);
@ -1561,7 +1559,8 @@ TlsAuthConfigAccessCallback (
HiiGetBrowserData (&gTlsAuthConfigGuid, mTlsAuthConfigStorageName, BufferSize, (UINT8 *) IfrNvData); HiiGetBrowserData (&gTlsAuthConfigGuid, mTlsAuthConfigStorageName, BufferSize, (UINT8 *) IfrNvData);
if ((Action != EFI_BROWSER_ACTION_CHANGED) && 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; Status = EFI_UNSUPPORTED;
goto EXIT; goto EXIT;
} }
@ -1592,12 +1591,19 @@ TlsAuthConfigAccessCallback (
CleanUpPage (LabelId, Private); CleanUpPage (LabelId, Private);
break; break;
case KEY_TLS_AUTH_CONFIG_ENROLL_CERT_FROM_FILE: 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); ChooseFile( NULL, NULL, UpdateCAFromFile, &File);
break; break;
case KEY_TLS_AUTH_CONFIG_VALUE_SAVE_AND_EXIT: case KEY_TLS_AUTH_CONFIG_VALUE_SAVE_AND_EXIT:
Status = EnrollCertDatabase (Private, EFI_TLS_CA_CERTIFICATE_VARIABLE); Status = EnrollCertDatabase (Private, EFI_TLS_CA_CERTIFICATE_VARIABLE);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
CleanFileContext (Private);
CreatePopUp ( CreatePopUp (
EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
&Key, &Key,
@ -1608,14 +1614,7 @@ TlsAuthConfigAccessCallback (
break; break;
case KEY_TLS_AUTH_CONFIG_VALUE_NO_SAVE_AND_EXIT: case KEY_TLS_AUTH_CONFIG_VALUE_NO_SAVE_AND_EXIT:
if (Private->FileContext->FHandle != NULL) { CleanFileContext (Private);
CloseFile (Private->FileContext->FHandle);
Private->FileContext->FHandle = NULL;
if (Private->FileContext->FileName!= NULL){
FreePool(Private->FileContext->FileName);
Private->FileContext->FileName = NULL;
}
}
if (Private->CertGuid!= NULL) { if (Private->CertGuid!= NULL) {
FreePool (Private->CertGuid); FreePool (Private->CertGuid);
@ -1667,6 +1666,8 @@ TlsAuthConfigAccessCallback (
default: default:
break; break;
} }
} else if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {
CleanFileContext (Private);
} }
EXIT: EXIT: