diff options
author | Ruiyu Ni <ruiyu.ni@intel.com> | 2016-07-12 13:56:04 +0800 |
---|---|---|
committer | Hao Wu <hao.a.wu@intel.com> | 2016-07-25 11:04:14 +0800 |
commit | e2098b9e6b2c26eb2c415faa0ce5ead2daae74c4 (patch) | |
tree | b5a972c5bc9e926cbde92f692a775f4f67c71b8f | |
parent | c84ccd98880b8561b357e8524630cfb00bdfce4b (diff) | |
download | edk2-platforms-e2098b9e6b2c26eb2c415faa0ce5ead2daae74c4.tar.xz |
ShellPkg/UefiShellBcfgCommandLib: Handle memory allocation failure
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
(cherry picked from commit 5945813f69f1d5864bb54982bf59ebd1057c4949)
-rw-r--r-- | ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c index bf35a35b98..9baeecc339 100644 --- a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c +++ b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c @@ -2,7 +2,7 @@ Main file for BCFG command.
(C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR>
- Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
@@ -553,33 +553,34 @@ BcfgAdd( if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellBcfgHiiHandle, L"bcfg", OptionStr);
} else {
- NewOrder = AllocateZeroPool((OrderCount+1)*sizeof(NewOrder[0]));
- ASSERT(NewOrder != NULL);
- CopyMem(NewOrder, CurrentOrder, (OrderCount)*sizeof(NewOrder[0]));
+ NewOrder = AllocateZeroPool ((OrderCount + 1) * sizeof (NewOrder[0]));
+ if (NewOrder != NULL) {
+ CopyMem (NewOrder, CurrentOrder, (OrderCount) * sizeof (NewOrder[0]));
- //
- // Insert target into order list
- //
- for (Index=OrderCount; Index > Position; Index--) {
- NewOrder[Index] = NewOrder[Index-1];
- }
+ //
+ // Insert target into order list
+ //
+ for (Index = OrderCount; Index > Position; Index--) {
+ NewOrder[Index] = NewOrder[Index - 1];
+ }
- NewOrder[Position] = (UINT16) TargetLocation;
- Status = gRT->SetVariable (
- Target == BcfgTargetBootOrder?L"BootOrder":L"DriverOrder",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,
- (OrderCount+1) * sizeof(UINT16),
- NewOrder
- );
+ NewOrder[Position] = (UINT16) TargetLocation;
+ Status = gRT->SetVariable (
+ Target == BcfgTargetBootOrder ? L"BootOrder" : L"DriverOrder",
+ &gEfiGlobalVariableGuid,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ (OrderCount + 1) * sizeof (UINT16),
+ NewOrder
+ );
- FreePool(NewOrder);
+ FreePool (NewOrder);
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellBcfgHiiHandle, L"bcfg", Target == BcfgTargetBootOrder?L"BootOrder":L"DriverOrder");
- ShellStatus = SHELL_INVALID_PARAMETER;
- } else {
- Print (L"bcfg: Add %s as %x\n", OptionStr, Position);
+ if (EFI_ERROR (Status)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellBcfgHiiHandle, L"bcfg", Target == BcfgTargetBootOrder ? L"BootOrder" : L"DriverOrder");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ Print (L"bcfg: Add %s as %x\n", OptionStr, Position);
+ }
}
}
}
|