MdeModulePkg/BootMaintUi: Add error handling codes when AllocatePool fail

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>
This commit is contained in:
Bi, Dandan 2016-07-05 16:53:11 +08:00 committed by Hao Wu
parent ae9026ddfa
commit a91f1a0e88
3 changed files with 35 additions and 26 deletions

View File

@ -379,6 +379,7 @@ ExtractFileNameFromDevicePath (
String = UiDevicePathToStr(DevicePath);
MatchString = String;
LastMatch = String;
FileName = NULL;
while(MatchString != NULL){
LastMatch = MatchString + 1;
@ -387,7 +388,9 @@ ExtractFileNameFromDevicePath (
Length = StrLen(LastMatch);
FileName = AllocateCopyPool ((Length + 1) * sizeof(CHAR16), LastMatch);
*(FileName + Length) = 0;
if (FileName != NULL) {
*(FileName + Length) = 0;
}
FreePool(String);

View File

@ -865,29 +865,33 @@ 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;
}

View File

@ -1,7 +1,7 @@
/** @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
@ -1020,17 +1020,19 @@ 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));