]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/BootMaintUi: Add error handling codes when AllocatePool fail
authorBi, Dandan <C:/Program Files (x86)/Git/o=Intel/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=Bi, Dandan08b>
Tue, 5 Jul 2016 08:53:11 +0000 (16:53 +0800)
committerHao Wu <hao.a.wu@intel.com>
Wed, 6 Jul 2016 08:23:02 +0000 (16:23 +0800)
The AllocateCopyPool in function ExtractFileNameFromDevicePath
may return NULL, so need to do error handling. This patch is to
add error handling codes for function ExtractFileNameFromDevicePath
and its caller functions.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c
MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c
MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c

index b35e938b4057faf16102f0badf191f8adfb89067..393091f39a84b40410c2dde06875f87eb3959ae7 100644 (file)
@@ -379,6 +379,7 @@ ExtractFileNameFromDevicePath (
   String = UiDevicePathToStr(DevicePath);\r
   MatchString = String;\r
   LastMatch   = String;\r
+  FileName    = NULL;\r
 \r
   while(MatchString != NULL){\r
     LastMatch   = MatchString + 1;\r
@@ -387,7 +388,9 @@ ExtractFileNameFromDevicePath (
 \r
   Length = StrLen(LastMatch);\r
   FileName = AllocateCopyPool ((Length + 1) * sizeof(CHAR16), LastMatch);\r
-  *(FileName + Length) = 0;\r
+  if (FileName != NULL) {\r
+    *(FileName + Length) = 0;\r
+  }\r
 \r
   FreePool(String);\r
 \r
index c660c731458a286ce14e216e3de227c3212e919e..890728aff5b69cfc2867b12633ceeed25c1178eb 100644 (file)
@@ -865,29 +865,33 @@ BootFromFile (
   EFI_BOOT_MANAGER_LOAD_OPTION BootOption;\r
   CHAR16                       *FileName;\r
 \r
+  FileName = NULL;\r
+\r
   FileName = ExtractFileNameFromDevicePath(FilePath);\r
-  EfiBootManagerInitializeLoadOption (\r
-    &BootOption,\r
-    0,\r
-    LoadOptionTypeBoot,\r
-    LOAD_OPTION_ACTIVE,\r
-    FileName,\r
-    FilePath,\r
-    NULL,\r
-    0\r
-    );\r
-  //\r
-  // Since current no boot from removable media directly is allowed */\r
-  //\r
-  gST->ConOut->ClearScreen (gST->ConOut);\r
+  if (FileName != NULL) {\r
+    EfiBootManagerInitializeLoadOption (\r
+      &BootOption,\r
+      0,\r
+      LoadOptionTypeBoot,\r
+      LOAD_OPTION_ACTIVE,\r
+      FileName,\r
+      FilePath,\r
+      NULL,\r
+      0\r
+      );\r
+    //\r
+    // Since current no boot from removable media directly is allowed */\r
+    //\r
+    gST->ConOut->ClearScreen (gST->ConOut);\r
 \r
-  BmmSetConsoleMode (FALSE);\r
-  EfiBootManagerBoot (&BootOption);\r
-  BmmSetConsoleMode (TRUE);\r
+    BmmSetConsoleMode (FALSE);\r
+    EfiBootManagerBoot (&BootOption);\r
+    BmmSetConsoleMode (TRUE);\r
 \r
-  FreePool(FileName);\r
+    FreePool(FileName);\r
 \r
-  EfiBootManagerFreeLoadOption (&BootOption);\r
+    EfiBootManagerFreeLoadOption (&BootOption);\r
+  }\r
 \r
   return FALSE;\r
 }\r
index 13a29db9f4e4728df07af6bb9b23713edecb103a..9e79826a6afaaea4e715774da6ae18087ad421a1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Dynamically update the pages.\r
 \r
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -1020,17 +1020,19 @@ UpdateOptionPage(
   CHAR16                *String;\r
   EFI_STRING_ID         StringToken;\r
 \r
+  String = NULL;\r
+\r
   if (DevicePath != NULL){\r
     String = ExtractFileNameFromDevicePath(DevicePath);\r
-    StringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, String, NULL);\r
-    FreePool(String);\r
-  } else {\r
+  }\r
+  if (String == NULL) {\r
     String = HiiGetString (CallbackData->BmmHiiHandle, STRING_TOKEN (STR_NULL_STRING), NULL);\r
     ASSERT (String != NULL);\r
-    StringToken =  HiiSetString (CallbackData->BmmHiiHandle, 0, String, NULL);\r
-    FreePool (String);\r
   }\r
 \r
+  StringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, String, NULL);\r
+  FreePool (String);\r
+\r
   if(FormId == FORM_BOOT_ADD_ID){\r
     if (!CallbackData->BmmFakeNvData.BootOptionChanged) {\r
       ZeroMem (CallbackData->BmmFakeNvData.BootOptionalData, sizeof (CallbackData->BmmFakeNvData.BootOptionalData));\r