public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource
@ 2017-04-10  4:30 Jiaxin Wu
  2017-04-13  1:49 ` Zhang, Chao B
  0 siblings, 1 reply; 3+ messages in thread
From: Jiaxin Wu @ 2017-04-10  4:30 UTC (permalink / raw)
  To: edk2-devel; +Cc: Zhang Chao B, Ye Ting, Fu Siyuan, Wu Jiaxin

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>
---
 NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c | 43 ++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c b/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c
index 81f7e7d..23442fe 100644
--- a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c
+++ b/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c
@@ -1559,11 +1559,12 @@ 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;
   }
 
   if (Action == EFI_BROWSER_ACTION_CHANGING) {
@@ -1590,26 +1591,54 @@ TlsAuthConfigAccessCallback (
       // Refresh selected file.
       //
       CleanUpPage (LabelId, Private);
       break;
     case KEY_TLS_AUTH_CONFIG_ENROLL_CERT_FROM_FILE:
+      //
+      // If the file is already opened, then close and 
+      // free the related resource first. 
+      //
+      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;
+        }
+      }
+      
       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)) {
+        //
+        // Close File and free the related resource. 
+        //
+        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;
+          }
+        }
+        
         CreatePopUp (
           EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
           &Key,
           L"ERROR: Enroll Cert Failure!",
           NULL
           );
       }
       break;
 
     case KEY_TLS_AUTH_CONFIG_VALUE_NO_SAVE_AND_EXIT:
+      //
+      // Close File and free the related resource. 
+      //
       if (Private->FileContext->FHandle != NULL) {
         CloseFile (Private->FileContext->FHandle);
         Private->FileContext->FHandle = NULL;
         if (Private->FileContext->FileName!= NULL){
           FreePool(Private->FileContext->FileName);
@@ -1665,10 +1694,22 @@ TlsAuthConfigAccessCallback (
       *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
       break;
     default:
       break;
     }
+  } else if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {
+    //
+    // Close File and free the related resource. 
+    //
+    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;
+      }
+    }
   }
 
 EXIT:
 
   if (!EFI_ERROR (Status)) {
-- 
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource
  2017-04-10  4:30 [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource Jiaxin Wu
@ 2017-04-13  1:49 ` Zhang, Chao B
  2017-04-13  7:36   ` Wu, Jiaxin
  0 siblings, 1 reply; 3+ messages in thread
From: Zhang, Chao B @ 2017-04-13  1:49 UTC (permalink / raw)
  To: Wu, Jiaxin, edk2-devel@lists.01.org; +Cc: Ye, Ting, Fu, Siyuan

Jiaxin:
   I would like to recommend a new function to close the file handle in private datastructure. The closing logic is now scattering around.

-----Original Message-----
From: Wu, Jiaxin 
Sent: Monday, April 10, 2017 12:31 PM
To: edk2-devel@lists.01.org
Cc: Zhang, Chao B <chao.b.zhang@intel.com>; Ye, Ting <ting.ye@intel.com>; Fu, Siyuan <siyuan.fu@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
Subject: [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource

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>
---
 NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c | 43 ++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c b/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c
index 81f7e7d..23442fe 100644
--- a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c
+++ b/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c
@@ -1559,11 +1559,12 @@ 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;
   }
 
   if (Action == EFI_BROWSER_ACTION_CHANGING) { @@ -1590,26 +1591,54 @@ TlsAuthConfigAccessCallback (
       // Refresh selected file.
       //
       CleanUpPage (LabelId, Private);
       break;
     case KEY_TLS_AUTH_CONFIG_ENROLL_CERT_FROM_FILE:
+      //
+      // If the file is already opened, then close and 
+      // free the related resource first. 
+      //
+      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;
+        }
+      }
+      
       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)) {
+        //
+        // Close File and free the related resource. 
+        //
+        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;
+          }
+        }
+        
         CreatePopUp (
           EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
           &Key,
           L"ERROR: Enroll Cert Failure!",
           NULL
           );
       }
       break;
 
     case KEY_TLS_AUTH_CONFIG_VALUE_NO_SAVE_AND_EXIT:
+      //
+      // Close File and free the related resource. 
+      //
       if (Private->FileContext->FHandle != NULL) {
         CloseFile (Private->FileContext->FHandle);
         Private->FileContext->FHandle = NULL;
         if (Private->FileContext->FileName!= NULL){
           FreePool(Private->FileContext->FileName);
@@ -1665,10 +1694,22 @@ TlsAuthConfigAccessCallback (
       *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
       break;
     default:
       break;
     }
+  } else if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {
+    //
+    // Close File and free the related resource. 
+    //
+    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;
+      }
+    }
   }
 
 EXIT:
 
   if (!EFI_ERROR (Status)) {
--
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource
  2017-04-13  1:49 ` Zhang, Chao B
@ 2017-04-13  7:36   ` Wu, Jiaxin
  0 siblings, 0 replies; 3+ messages in thread
From: Wu, Jiaxin @ 2017-04-13  7:36 UTC (permalink / raw)
  To: Zhang, Chao B, edk2-devel@lists.01.org; +Cc: Ye, Ting, Fu, Siyuan

Thanks, chao, I will refine the patch as your comments.


> -----Original Message-----
> From: Zhang, Chao B
> Sent: Thursday, April 13, 2017 9:49 AM
> To: Wu, Jiaxin <jiaxin.wu@intel.com>; edk2-devel@lists.01.org
> Cc: Ye, Ting <ting.ye@intel.com>; Fu, Siyuan <siyuan.fu@intel.com>
> Subject: RE: [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file
> related resource
> 
> Jiaxin:
>    I would like to recommend a new function to close the file handle in private
> datastructure. The closing logic is now scattering around.
> 
> -----Original Message-----
> From: Wu, Jiaxin
> Sent: Monday, April 10, 2017 12:31 PM
> To: edk2-devel@lists.01.org
> Cc: Zhang, Chao B <chao.b.zhang@intel.com>; Ye, Ting <ting.ye@intel.com>;
> Fu, Siyuan <siyuan.fu@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
> Subject: [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file
> related resource
> 
> 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>
> ---
>  NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c | 43
> ++++++++++++++++++++++++-
>  1 file changed, 42 insertions(+), 1 deletion(-)
> 
> diff --git a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c
> b/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c
> index 81f7e7d..23442fe 100644
> --- a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c
> +++ b/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c
> @@ -1559,11 +1559,12 @@ 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;
>    }
> 
>    if (Action == EFI_BROWSER_ACTION_CHANGING) { @@ -1590,26 +1591,54
> @@ TlsAuthConfigAccessCallback (
>        // Refresh selected file.
>        //
>        CleanUpPage (LabelId, Private);
>        break;
>      case KEY_TLS_AUTH_CONFIG_ENROLL_CERT_FROM_FILE:
> +      //
> +      // If the file is already opened, then close and
> +      // free the related resource first.
> +      //
> +      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;
> +        }
> +      }
> +
>        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)) {
> +        //
> +        // Close File and free the related resource.
> +        //
> +        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;
> +          }
> +        }
> +
>          CreatePopUp (
>            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
>            &Key,
>            L"ERROR: Enroll Cert Failure!",
>            NULL
>            );
>        }
>        break;
> 
>      case KEY_TLS_AUTH_CONFIG_VALUE_NO_SAVE_AND_EXIT:
> +      //
> +      // Close File and free the related resource.
> +      //
>        if (Private->FileContext->FHandle != NULL) {
>          CloseFile (Private->FileContext->FHandle);
>          Private->FileContext->FHandle = NULL;
>          if (Private->FileContext->FileName!= NULL){
>            FreePool(Private->FileContext->FileName);
> @@ -1665,10 +1694,22 @@ TlsAuthConfigAccessCallback (
>        *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
>        break;
>      default:
>        break;
>      }
> +  } else if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {
> +    //
> +    // Close File and free the related resource.
> +    //
> +    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;
> +      }
> +    }
>    }
> 
>  EXIT:
> 
>    if (!EFI_ERROR (Status)) {
> --
> 1.9.5.msysgit.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-13  7:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-10  4:30 [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource Jiaxin Wu
2017-04-13  1:49 ` Zhang, Chao B
2017-04-13  7:36   ` Wu, Jiaxin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox