The function AllocateCopyPool may return NULL, so need to do check
after calling it. This patch is to enhance the related 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>
---
 .../SecureBootConfigDxe/SecureBootConfigFileExplorer.c        | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git 
a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
 
b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
index 2adb85c..7787d64 100644
--- 
a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
+++ 
b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
@@ -243,19 +243,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,12 +281,16 @@ UpdatePage(
   )
 {
   CHAR16                *FileName;
   EFI_STRING_ID         StringToken;
 
-  if (FilePath != NULL){
+  FileName = NULL;
+
+  if (FilePath != NULL) {
     FileName = ExtractFileNameFromDevicePath(FilePath);
+  }
+  if (FileName != NULL) {
     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);
-- 
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