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.d...@intel.com> Cc: Hao Wu <hao.a...@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Dandan Bi <dandan...@intel.com> Reviewed-by: Eric Dong <eric.d...@intel.com> --- .../BootMaintenanceManagerUiLib/BootMaintenance.c | 5 ++- .../BootMaintenanceManagerUiLib/BootOption.c | 42 ++++++++++++---------- .../BootMaintenanceManagerUiLib/UpdatePage.c | 14 ++++---- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c index b35e938..393091f 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c @@ -377,19 +377,22 @@ ExtractFileNameFromDevicePath ( ASSERT(DevicePath != NULL); String = UiDevicePathToStr(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; } diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c index c660c73..890728a 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c @@ -863,33 +863,37 @@ BootFromFile ( ) { EFI_BOOT_MANAGER_LOAD_OPTION BootOption; CHAR16 *FileName; + FileName = NULL; + FileName = ExtractFileNameFromDevicePath(FilePath); - EfiBootManagerInitializeLoadOption ( - &BootOption, - 0, - LoadOptionTypeBoot, - LOAD_OPTION_ACTIVE, - FileName, - FilePath, - NULL, - 0 - ); - // - // Since current no boot from removable media directly is allowed */ - // - gST->ConOut->ClearScreen (gST->ConOut); + if (FileName != NULL) { + EfiBootManagerInitializeLoadOption ( + &BootOption, + 0, + LoadOptionTypeBoot, + LOAD_OPTION_ACTIVE, + FileName, + FilePath, + NULL, + 0 + ); + // + // Since current no boot from removable media directly is allowed */ + // + gST->ConOut->ClearScreen (gST->ConOut); - BmmSetConsoleMode (FALSE); - EfiBootManagerBoot (&BootOption); - BmmSetConsoleMode (TRUE); + BmmSetConsoleMode (FALSE); + EfiBootManagerBoot (&BootOption); + BmmSetConsoleMode (TRUE); - FreePool(FileName); + FreePool(FileName); - EfiBootManagerFreeLoadOption (&BootOption); + EfiBootManagerFreeLoadOption (&BootOption); + } return FALSE; } /** diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c index 13a29db..9e79826 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c @@ -1,9 +1,9 @@ /** @file Dynamically update the pages. -Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -1018,21 +1018,23 @@ UpdateOptionPage( ) { CHAR16 *String; EFI_STRING_ID StringToken; + String = NULL; + if (DevicePath != NULL){ String = ExtractFileNameFromDevicePath(DevicePath); - StringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, String, NULL); - FreePool(String); - } else { + } + if (String == NULL) { String = HiiGetString (CallbackData->BmmHiiHandle, STRING_TOKEN (STR_NULL_STRING), NULL); ASSERT (String != NULL); - StringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, String, NULL); - FreePool (String); } + StringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, String, NULL); + FreePool (String); + if(FormId == FORM_BOOT_ADD_ID){ if (!CallbackData->BmmFakeNvData.BootOptionChanged) { ZeroMem (CallbackData->BmmFakeNvData.BootOptionalData, sizeof (CallbackData->BmmFakeNvData.BootOptionalData)); ZeroMem (CallbackData->BmmFakeNvData.BootDescriptionData, sizeof (CallbackData->BmmFakeNvData.BootDescriptionData)); } -- 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel