summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2016-07-12 17:38:06 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2016-07-18 10:55:20 +0800
commit107d05a433c3ea5d877baaa4867ede7708323d38 (patch)
tree1856a66edf3ddc4b37b08c596d117facff731c55
parent2c7c3b87bf43ce0977106546220b96e4d4b1ca36 (diff)
downloadedk2-107d05a433c3ea5d877baaa4867ede7708323d38.tar.gz
edk2-107d05a433c3ea5d877baaa4867ede7708323d38.tar.bz2
edk2-107d05a433c3ea5d877baaa4867ede7708323d38.zip
ShellPkg/UefiShellCommandLib.c: 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>
-rw-r--r--ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
index 48e4d4af0d..35e0611a8e 100644
--- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
+++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
@@ -1,7 +1,7 @@
/** @file
Provides interface to shell internal functions for shell commands.
- Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
@@ -546,9 +546,14 @@ ShellCommandRegisterCommandName (
// allocate memory for new struct
//
Node = AllocateZeroPool(sizeof(SHELL_COMMAND_INTERNAL_LIST_ENTRY));
- ASSERT(Node != NULL);
+ if (Node == NULL) {
+ return RETURN_OUT_OF_RESOURCES;
+ }
Node->CommandString = AllocateCopyPool(StrSize(CommandString), CommandString);
- ASSERT(Node->CommandString != NULL);
+ if (Node->CommandString == NULL) {
+ FreePool (Node);
+ return RETURN_OUT_OF_RESOURCES;
+ }
Node->GetManFileName = GetManFileName;
Node->CommandHandler = CommandHandler;
@@ -807,11 +812,20 @@ ShellCommandRegisterAlias (
// allocate memory for new struct
//
Node = AllocateZeroPool(sizeof(ALIAS_LIST));
- ASSERT(Node != NULL);
+ if (Node == NULL) {
+ return RETURN_OUT_OF_RESOURCES;
+ }
Node->CommandString = AllocateCopyPool(StrSize(Command), Command);
+ if (Node->CommandString == NULL) {
+ FreePool (Node);
+ return RETURN_OUT_OF_RESOURCES;
+ }
Node->Alias = AllocateCopyPool(StrSize(Alias), Alias);
- ASSERT(Node->CommandString != NULL);
- ASSERT(Node->Alias != NULL);
+ if (Node->Alias == NULL) {
+ FreePool (Node->CommandString);
+ FreePool (Node);
+ return RETURN_OUT_OF_RESOURCES;
+ }
InsertHeadList (&mAliasList.Link, &Node->Link);
@@ -1303,7 +1317,10 @@ ShellCommandCreateInitialMappingsAndPaths(
// Get all Device Paths
//
DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);
- ASSERT(DevicePathList != NULL);
+ if (DevicePathList == NULL) {
+ SHELL_FREE_NON_NULL (HandleList);
+ return EFI_OUT_OF_RESOURCES;
+ }
for (Count = 0 ; HandleList[Count] != NULL ; Count++) {
DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]);
@@ -1360,7 +1377,10 @@ ShellCommandCreateInitialMappingsAndPaths(
// Get all Device Paths
//
DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);
- ASSERT(DevicePathList != NULL);
+ if (DevicePathList == NULL) {
+ SHELL_FREE_NON_NULL (HandleList);
+ return EFI_OUT_OF_RESOURCES;
+ }
for (Count = 0 ; HandleList[Count] != NULL ; Count++) {
DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]);