The function AllocateCopyPool may return NULL, so need to do check
after calling it. This patch is to enhance the related logic.

Notes:
Difference with V1:
-Update the function description.
-Remove the ASSERT in UpdatePage and enhance the logic.

Cc: Chao Zhang <chao.b.zh...@intel.com>
Cc: Qiu Shumin <shumin....@intel.com>
Cc: Eric Dong <eric.d...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan...@intel.com>
---
 .../SecureBootConfigFileExplorer.c                 | 30 +++++++++++++++-------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git 
a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
 
b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
index 2adb85c..ec172cd 100644
--- 
a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
+++ 
b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
@@ -220,15 +220,17 @@ OpenFileByDevicePath(
 }
 
 
 /**
   Extract filename from device path. The returned buffer is allocated using 
AllocateCopyPool.
-  The caller is responsible for freeing the allocated buffer using FreePool().
+  The caller is responsible for freeing the allocated buffer using FreePool(). 
If return NULL
+  means not enough memory resource.
 
   @param DevicePath       Device path.
 
-  @return                 A new allocated string that represents the file name.
+  @retval NULL            Not enough memory resourece for AllocateCopyPool.
+  @retval Other           A new allocated string that represents the file name.
 
 **/
 CHAR16 *
 ExtractFileNameFromDevicePath (
   IN   EFI_DEVICE_PATH_PROTOCOL *DevicePath
@@ -243,19 +245,22 @@ ExtractFileNameFromDevicePath (
   ASSERT(DevicePath != NULL);
 
   String = DevicePathToStr(DevicePath);
   MatchString = String;
   LastMatch   = String;
+  FileName    = NULL;
 
   while(MatchString != NULL){
     LastMatch   = MatchString + 1;
     MatchString = StrStr(LastMatch,L"\\");
   }
 
   Length = StrLen(LastMatch);
   FileName = AllocateCopyPool ((Length + 1) * sizeof(CHAR16), LastMatch);
-  *(FileName + Length) = 0;
+  if (FileName != NULL) {
+    *(FileName + Length) = 0;
+  }
 
   FreePool(String);
 
   return FileName;
 }
@@ -278,18 +283,25 @@ UpdatePage(
   )
 {
   CHAR16                *FileName;
   EFI_STRING_ID         StringToken;
 
-  if (FilePath != NULL){
+  FileName = NULL;
+
+  if (FilePath != NULL) {
     FileName = ExtractFileNameFromDevicePath(FilePath);
-    StringToken = HiiSetString (gSecureBootPrivateData->HiiHandle, 0, 
FileName, NULL);
-  } else {
-    FileName = HiiGetString (gSecureBootPrivateData->HiiHandle, STRING_TOKEN 
(STR_NULL), NULL);
-    ASSERT (FileName != NULL);
-    StringToken =  HiiSetString (gSecureBootPrivateData->HiiHandle, 0, 
FileName, NULL);
   }
+  if (FileName == NULL) {
+    //
+    // FileName = NULL has two case:
+    // 1. FilePath == NULL, not select file.
+    // 2. FilePath != NULL, but  ExtractFileNameFromDevicePath return NULL not 
enough memory resource.
+    // In these two case, not need to update the form, and exit the caller 
function.
+    //
+    return TRUE;
+  }
+  StringToken =  HiiSetString (gSecureBootPrivateData->HiiHandle, 0, FileName, 
NULL);
 
   gSecureBootPrivateData->FileContext->FileName = FileName;
 
   OpenFileByDevicePath(
     &FilePath,
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to