ShellPkg/IfConfig: 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>
This commit is contained in:
@ -129,6 +129,26 @@ VAR_CHECK_ITEM mSetCheckList[] = {
|
|||||||
|
|
||||||
STATIC CONST CHAR16 PermanentString[10] = L"PERMANENT";
|
STATIC CONST CHAR16 PermanentString[10] = L"PERMANENT";
|
||||||
|
|
||||||
|
/**
|
||||||
|
Free the ARG_LIST.
|
||||||
|
|
||||||
|
@param List Pointer to ARG_LIST to free.
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
FreeArgList (
|
||||||
|
ARG_LIST *List
|
||||||
|
)
|
||||||
|
{
|
||||||
|
ARG_LIST *Next;
|
||||||
|
while (List->Next != NULL) {
|
||||||
|
Next = List->Next;
|
||||||
|
FreePool (List);
|
||||||
|
List = Next;
|
||||||
|
}
|
||||||
|
|
||||||
|
FreePool (List);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Split a string with specified separator and save the substring to a list.
|
Split a string with specified separator and save the substring to a list.
|
||||||
|
|
||||||
@ -157,14 +177,18 @@ SplitStrToList (
|
|||||||
// Copy the CONST string to a local copy.
|
// Copy the CONST string to a local copy.
|
||||||
//
|
//
|
||||||
Str = AllocateCopyPool (StrSize (String), String);
|
Str = AllocateCopyPool (StrSize (String), String);
|
||||||
ASSERT (Str != NULL);
|
if (Str == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
ArgStr = Str;
|
ArgStr = Str;
|
||||||
|
|
||||||
//
|
//
|
||||||
// init a node for the list head.
|
// init a node for the list head.
|
||||||
//
|
//
|
||||||
ArgNode = (ARG_LIST *) AllocateZeroPool (sizeof (ARG_LIST));
|
ArgNode = (ARG_LIST *) AllocateZeroPool (sizeof (ARG_LIST));
|
||||||
ASSERT (ArgNode != NULL);
|
if (ArgNode == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
ArgList = ArgNode;
|
ArgList = ArgNode;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -176,7 +200,14 @@ SplitStrToList (
|
|||||||
ArgNode->Arg = ArgStr;
|
ArgNode->Arg = ArgStr;
|
||||||
ArgStr = Str + 1;
|
ArgStr = Str + 1;
|
||||||
ArgNode->Next = (ARG_LIST *) AllocateZeroPool (sizeof (ARG_LIST));
|
ArgNode->Next = (ARG_LIST *) AllocateZeroPool (sizeof (ARG_LIST));
|
||||||
ASSERT (ArgNode->Next != NULL);
|
if (ArgNode->Next == NULL) {
|
||||||
|
//
|
||||||
|
// Free the local copy of string stored in the first node
|
||||||
|
//
|
||||||
|
FreePool (ArgList->Arg);
|
||||||
|
FreeArgList (ArgList);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
ArgNode = ArgNode->Next;
|
ArgNode = ArgNode->Next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1083,7 +1114,11 @@ IfConfigSetInterfaceInfo (
|
|||||||
}
|
}
|
||||||
|
|
||||||
Dns = AllocatePool (Index * sizeof (EFI_IPv4_ADDRESS));
|
Dns = AllocatePool (Index * sizeof (EFI_IPv4_ADDRESS));
|
||||||
ASSERT(Dns != NULL);
|
if (Dns == NULL) {
|
||||||
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellNetwork1HiiHandle, L"ifconfig");
|
||||||
|
ShellStatus = SHELL_OUT_OF_RESOURCES;
|
||||||
|
goto ON_EXIT;
|
||||||
|
}
|
||||||
Tmp = VarArg;
|
Tmp = VarArg;
|
||||||
Index = 0;
|
Index = 0;
|
||||||
while (Tmp != NULL) {
|
while (Tmp != NULL) {
|
||||||
@ -1193,8 +1228,6 @@ IfConfigCleanup (
|
|||||||
LIST_ENTRY *Entry;
|
LIST_ENTRY *Entry;
|
||||||
LIST_ENTRY *NextEntry;
|
LIST_ENTRY *NextEntry;
|
||||||
IFCONFIG_INTERFACE_CB *IfCb;
|
IFCONFIG_INTERFACE_CB *IfCb;
|
||||||
ARG_LIST *ArgNode;
|
|
||||||
ARG_LIST *ArgHead;
|
|
||||||
|
|
||||||
ASSERT (Private != NULL);
|
ASSERT (Private != NULL);
|
||||||
|
|
||||||
@ -1202,15 +1235,7 @@ IfConfigCleanup (
|
|||||||
// Clean the list which save the set config Args.
|
// Clean the list which save the set config Args.
|
||||||
//
|
//
|
||||||
if (Private->VarArg != NULL) {
|
if (Private->VarArg != NULL) {
|
||||||
ArgHead = Private->VarArg;
|
FreeArgList (Private->VarArg);
|
||||||
|
|
||||||
while (ArgHead->Next != NULL) {
|
|
||||||
ArgNode = ArgHead->Next;
|
|
||||||
FreePool (ArgHead);
|
|
||||||
ArgHead = ArgNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
FreePool (ArgHead);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Private->IfName != NULL) {
|
if (Private->IfName != NULL) {
|
||||||
@ -1325,11 +1350,15 @@ ShellCommandRunIfconfig (
|
|||||||
ValueStr = ShellCommandLineGetValue (ParamPackage, L"-l");
|
ValueStr = ShellCommandLineGetValue (ParamPackage, L"-l");
|
||||||
if (ValueStr != NULL) {
|
if (ValueStr != NULL) {
|
||||||
Str = AllocateCopyPool (StrSize (ValueStr), ValueStr);
|
Str = AllocateCopyPool (StrSize (ValueStr), ValueStr);
|
||||||
ASSERT (Str != NULL);
|
if (Str == NULL) {
|
||||||
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellNetwork1HiiHandle, L"ifconfig");
|
||||||
|
ShellStatus = SHELL_OUT_OF_RESOURCES;
|
||||||
|
goto ON_EXIT;
|
||||||
|
}
|
||||||
Private->IfName = Str;
|
Private->IfName = Str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// To get interface name for the clear option.
|
// To get interface name for the clear option.
|
||||||
//
|
//
|
||||||
@ -1338,7 +1367,11 @@ ShellCommandRunIfconfig (
|
|||||||
ValueStr = ShellCommandLineGetValue (ParamPackage, L"-r");
|
ValueStr = ShellCommandLineGetValue (ParamPackage, L"-r");
|
||||||
if (ValueStr != NULL) {
|
if (ValueStr != NULL) {
|
||||||
Str = AllocateCopyPool (StrSize (ValueStr), ValueStr);
|
Str = AllocateCopyPool (StrSize (ValueStr), ValueStr);
|
||||||
ASSERT (Str != NULL);
|
if (Str == NULL) {
|
||||||
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellNetwork1HiiHandle, L"ifconfig");
|
||||||
|
ShellStatus = SHELL_OUT_OF_RESOURCES;
|
||||||
|
goto ON_EXIT;
|
||||||
|
}
|
||||||
Private->IfName = Str;
|
Private->IfName = Str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1357,8 +1390,12 @@ ShellCommandRunIfconfig (
|
|||||||
//
|
//
|
||||||
// To split the configuration into multi-section.
|
// To split the configuration into multi-section.
|
||||||
//
|
//
|
||||||
ArgList = SplitStrToList (ValueStr, L' ');
|
ArgList = SplitStrToList (ValueStr, L' ');
|
||||||
ASSERT (ArgList != NULL);
|
if (ArgList == NULL) {
|
||||||
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellNetwork1HiiHandle, L"ifconfig");
|
||||||
|
ShellStatus = SHELL_OUT_OF_RESOURCES;
|
||||||
|
goto ON_EXIT;
|
||||||
|
}
|
||||||
|
|
||||||
Private->OpCode = IfConfigOpSet;
|
Private->OpCode = IfConfigOpSet;
|
||||||
Private->IfName = ArgList->Arg;
|
Private->IfName = ArgList->Arg;
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#string STR_GEN_FILE_NF #language en-US "%H%s%N: File not found - '%H%s%N'\r\n"
|
#string STR_GEN_FILE_NF #language en-US "%H%s%N: File not found - '%H%s%N'\r\n"
|
||||||
#string STR_GEN_IS_DIR #language en-US "%H%s%N: '%H%s%N' is a directory\r\n"
|
#string STR_GEN_IS_DIR #language en-US "%H%s%N: '%H%s%N' is a directory\r\n"
|
||||||
#string STR_GEN_PROTOCOL_NF #language en-US "%H%s%N: The protocol '%H%s%N' is required and not found (%g).\r\n"
|
#string STR_GEN_PROTOCOL_NF #language en-US "%H%s%N: The protocol '%H%s%N' is required and not found (%g).\r\n"
|
||||||
|
#string STR_GEN_OUT_MEM #language en-US "%H%s%N: Memory allocation was not successful.\r\n"
|
||||||
|
|
||||||
#string STR_PING_INVALID_SOURCE #language en-US "%Ping: Require source interface option\r\n"
|
#string STR_PING_INVALID_SOURCE #language en-US "%Ping: Require source interface option\r\n"
|
||||||
#string STR_PING_CONFIG #language en-US "Config %r\r\n"
|
#string STR_PING_CONFIG #language en-US "Config %r\r\n"
|
||||||
|
Reference in New Issue
Block a user