Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));\r
\r
AlignedNode = AllocateCopyPool (DevicePathNodeLength(FilePath), FilePath);\r
ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));\r
\r
AlignedNode = AllocateCopyPool (DevicePathNodeLength(FilePath), FilePath);\r
- ASSERT (AlignedNode != NULL);\r
+ if (AlignedNode == NULL) {\r
+ FreePool (PathForReturn);\r
+ return NULL;\r
+ }\r
\r
// File Path Device Path Nodes 'can optionally add a "\" separator to\r
// the beginning and/or the end of the Path Name string.'\r
\r
// File Path Device Path Nodes 'can optionally add a "\" separator to\r
// the beginning and/or the end of the Path Name string.'\r
; !EFI_ERROR(Status) && !NoFile\r
; Status = FileHandleFindNextFile(FileDirHandle, FileInfo, &NoFile)\r
){\r
; !EFI_ERROR(Status) && !NoFile\r
; Status = FileHandleFindNextFile(FileDirHandle, FileInfo, &NoFile)\r
){\r
+ if (ShellFileList == NULL) {\r
+ ShellFileList = (EFI_SHELL_FILE_INFO*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
+ if (ShellFileList == NULL) {\r
+ SHELL_FREE_NON_NULL (BasePath);\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ InitializeListHead(&ShellFileList->Link);\r
+ }\r
//\r
// allocate a new EFI_SHELL_FILE_INFO and populate it...\r
//\r
//\r
// allocate a new EFI_SHELL_FILE_INFO and populate it...\r
//\r
FileInfo->FileName,\r
NULL, // no handle since not open\r
FileInfo);\r
FileInfo->FileName,\r
NULL, // no handle since not open\r
FileInfo);\r
-\r
- if (ShellFileList == NULL) {\r
- ShellFileList = (EFI_SHELL_FILE_INFO*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
- ASSERT(ShellFileList != NULL);\r
- InitializeListHead(&ShellFileList->Link);\r
+ if (ShellFileListItem == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ //\r
+ // Free resources outside the loop.\r
+ //\r
+ break;\r
}\r
InsertTailList(&ShellFileList->Link, &ShellFileListItem->Link);\r
}\r
}\r
InsertTailList(&ShellFileList->Link, &ShellFileListItem->Link);\r
}\r
; NextFilePatternStart++);\r
\r
CurrentFilePattern = AllocateZeroPool((NextFilePatternStart-FilePattern+1)*sizeof(CHAR16));\r
; NextFilePatternStart++);\r
\r
CurrentFilePattern = AllocateZeroPool((NextFilePatternStart-FilePattern+1)*sizeof(CHAR16));\r
- ASSERT(CurrentFilePattern != NULL);\r
+ if (CurrentFilePattern == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
StrnCpyS(CurrentFilePattern, NextFilePatternStart-FilePattern+1, FilePattern, NextFilePatternStart-FilePattern);\r
\r
if (CurrentFilePattern[0] == CHAR_NULL\r
StrnCpyS(CurrentFilePattern, NextFilePatternStart-FilePattern+1, FilePattern, NextFilePatternStart-FilePattern);\r
\r
if (CurrentFilePattern[0] == CHAR_NULL\r
// copy the information we need into a new Node\r
//\r
NewShellNode = InternalDuplicateShellFileInfo(ShellInfoNode, FALSE);\r
// copy the information we need into a new Node\r
//\r
NewShellNode = InternalDuplicateShellFileInfo(ShellInfoNode, FALSE);\r
- ASSERT(NewShellNode != NULL);\r
if (NewShellNode == NULL) {\r
Status = EFI_OUT_OF_RESOURCES;\r
}\r
if (NewShellNode == NULL) {\r
Status = EFI_OUT_OF_RESOURCES;\r
}\r
&& (Command[StrLen(Command)-4] == L'.')\r
) {\r
FixCommand = AllocateZeroPool(StrSize(Command) - 4 * sizeof (CHAR16));\r
&& (Command[StrLen(Command)-4] == L'.')\r
) {\r
FixCommand = AllocateZeroPool(StrSize(Command) - 4 * sizeof (CHAR16));\r
- ASSERT(FixCommand != NULL);\r
+ if (FixCommand == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
\r
StrnCpyS( FixCommand, \r
(StrSize(Command) - 4 * sizeof (CHAR16))/sizeof(CHAR16), \r
\r
StrnCpyS( FixCommand, \r
(StrSize(Command) - 4 * sizeof (CHAR16))/sizeof(CHAR16), \r
// Convert to lowercase to make aliases case-insensitive\r
if (Alias != NULL) {\r
AliasLower = AllocateCopyPool (StrSize (Alias), Alias);\r
// Convert to lowercase to make aliases case-insensitive\r
if (Alias != NULL) {\r
AliasLower = AllocateCopyPool (StrSize (Alias), Alias);\r
- ASSERT (AliasLower != NULL);\r
+ if (AliasLower == NULL) {\r
+ return NULL;\r
+ }\r
ToLower (AliasLower);\r
\r
if (Volatile == NULL) {\r
ToLower (AliasLower);\r
\r
if (Volatile == NULL) {\r
// Convert to lowercase to make aliases case-insensitive\r
if (Alias != NULL) {\r
AliasLower = AllocateCopyPool (StrSize (Alias), Alias);\r
// Convert to lowercase to make aliases case-insensitive\r
if (Alias != NULL) {\r
AliasLower = AllocateCopyPool (StrSize (Alias), Alias);\r
- ASSERT (AliasLower != NULL);\r
+ if (AliasLower == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
ToLower (AliasLower);\r
} else {\r
AliasLower = NULL;\r
ToLower (AliasLower);\r
} else {\r
AliasLower = NULL;\r
EFI_HANDLE *Buffer;\r
UINTN HandleCounter;\r
SHELL_PROTOCOL_HANDLE_LIST *OldProtocolNode;\r
EFI_HANDLE *Buffer;\r
UINTN HandleCounter;\r
SHELL_PROTOCOL_HANDLE_LIST *OldProtocolNode;\r
+ EFI_SHELL_PROTOCOL *OldShell;\r
\r
if (NewShell == NULL) {\r
return (EFI_INVALID_PARAMETER);\r
\r
if (NewShell == NULL) {\r
return (EFI_INVALID_PARAMETER);\r
// now overwrite each of them, but save the info to restore when we end.\r
//\r
for (HandleCounter = 0 ; HandleCounter < (BufferSize/sizeof(EFI_HANDLE)) ; HandleCounter++) {\r
// now overwrite each of them, but save the info to restore when we end.\r
//\r
for (HandleCounter = 0 ; HandleCounter < (BufferSize/sizeof(EFI_HANDLE)) ; HandleCounter++) {\r
- OldProtocolNode = AllocateZeroPool(sizeof(SHELL_PROTOCOL_HANDLE_LIST));\r
- ASSERT(OldProtocolNode != NULL);\r
Status = gBS->OpenProtocol(Buffer[HandleCounter],\r
&gEfiShellProtocolGuid,\r
Status = gBS->OpenProtocol(Buffer[HandleCounter],\r
&gEfiShellProtocolGuid,\r
- (VOID **) &(OldProtocolNode->Interface),\r
gImageHandle,\r
NULL,\r
EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
);\r
if (!EFI_ERROR(Status)) {\r
gImageHandle,\r
NULL,\r
EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
);\r
if (!EFI_ERROR(Status)) {\r
+ OldProtocolNode = AllocateZeroPool(sizeof(SHELL_PROTOCOL_HANDLE_LIST));\r
+ if (OldProtocolNode == NULL && !IsListEmpty (&ShellInfoObject.OldShellList.Link)) {\r
+ CleanUpShellProtocol (&mShellProtocol);\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ break;\r
+ }\r
//\r
// reinstall over the old one...\r
//\r
//\r
// reinstall over the old one...\r
//\r
- OldProtocolNode->Handle = Buffer[HandleCounter];\r
+ OldProtocolNode->Handle = Buffer[HandleCounter];\r
+ OldProtocolNode->Interface = OldShell;\r
Status = gBS->ReinstallProtocolInterface(\r
OldProtocolNode->Handle,\r
&gEfiShellProtocolGuid,\r
Status = gBS->ReinstallProtocolInterface(\r
OldProtocolNode->Handle,\r
&gEfiShellProtocolGuid,\r
@retval EFI_SUCCESS The operation was successful.\r
**/\r
EFI_STATUS\r
@retval EFI_SUCCESS The operation was successful.\r
**/\r
EFI_STATUS\r
CleanUpShellProtocol (\r
IN OUT EFI_SHELL_PROTOCOL *NewShell\r
)\r
{\r
CleanUpShellProtocol (\r
IN OUT EFI_SHELL_PROTOCOL *NewShell\r
)\r
{\r
SHELL_PROTOCOL_HANDLE_LIST *Node2;\r
SHELL_PROTOCOL_HANDLE_LIST *Node2;\r
- EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;\r
\r
//\r
// if we need to restore old protocols...\r
//\r
if (!IsListEmpty(&ShellInfoObject.OldShellList.Link)) {\r
\r
//\r
// if we need to restore old protocols...\r
//\r
if (!IsListEmpty(&ShellInfoObject.OldShellList.Link)) {\r
- for (Node2 = (SHELL_PROTOCOL_HANDLE_LIST *)GetFirstNode(&ShellInfoObject.OldShellList.Link)\r
+ for (Node2 = (SHELL_PROTOCOL_HANDLE_LIST *) GetFirstNode (&ShellInfoObject.OldShellList.Link)\r
; !IsListEmpty (&ShellInfoObject.OldShellList.Link)\r
; !IsListEmpty (&ShellInfoObject.OldShellList.Link)\r
- ; Node2 = (SHELL_PROTOCOL_HANDLE_LIST *)GetFirstNode(&ShellInfoObject.OldShellList.Link)\r
- ){\r
- RemoveEntryList(&Node2->Link);\r
- Status = gBS->ReinstallProtocolInterface(Node2->Handle,\r
- &gEfiShellProtocolGuid,\r
- NewShell,\r
- Node2->Interface);\r
- FreePool(Node2);\r
+ ; Node2 = (SHELL_PROTOCOL_HANDLE_LIST *) GetFirstNode (&ShellInfoObject.OldShellList.Link)\r
+ ) {\r
+ RemoveEntryList (&Node2->Link);\r
+ gBS->ReinstallProtocolInterface (Node2->Handle, &gEfiShellProtocolGuid, NewShell, Node2->Interface);\r
+ FreePool (Node2);\r
}\r
} else {\r
//\r
// no need to restore\r
//\r
}\r
} else {\r
//\r
// no need to restore\r
//\r
- Status = gBS->UninstallProtocolInterface(gImageHandle,\r
- &gEfiShellProtocolGuid,\r
- NewShell);\r
+ gBS->UninstallProtocolInterface (gImageHandle, &gEfiShellProtocolGuid, NewShell);\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Cleanup the shell environment.\r
+\r
+ @param[in, out] NewShell The pointer to the new shell protocol structure.\r
+\r
+ @retval EFI_SUCCESS The operation was successful.\r
+**/\r
+EFI_STATUS\r
+CleanUpShellEnvironment (\r
+ IN OUT EFI_SHELL_PROTOCOL *NewShell\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;\r
+ \r
+ CleanUpShellProtocol (NewShell);\r
+\r
Status = gBS->CloseEvent(NewShell->ExecutionBreak);\r
NewShell->ExecutionBreak = NULL;\r
\r
Status = gBS->CloseEvent(NewShell->ExecutionBreak);\r
NewShell->ExecutionBreak = NULL;\r
\r
manipulation, and initialization of EFI_SHELL_PROTOCOL.\r
\r
(C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
manipulation, and initialization of EFI_SHELL_PROTOCOL.\r
\r
(C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
- Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
- Opposite of CreatePopulateInstallShellProtocol. \r
+ Opposite of CreatePopulateInstallShellProtocol.\r
\r
Free all memory and restore the system to the state it was in before calling\r
CreatePopulateInstallShellProtocol.\r
\r
Free all memory and restore the system to the state it was in before calling\r
CreatePopulateInstallShellProtocol.\r
@retval EFI_SUCCESS The operation was successful.\r
**/\r
EFI_STATUS\r
@retval EFI_SUCCESS The operation was successful.\r
**/\r
EFI_STATUS\r
CleanUpShellProtocol (\r
IN OUT EFI_SHELL_PROTOCOL *NewShell\r
);\r
\r
CleanUpShellProtocol (\r
IN OUT EFI_SHELL_PROTOCOL *NewShell\r
);\r
\r
+/**\r
+ Cleanup the shell environment.\r
+\r
+ @param[in, out] NewShell The pointer to the new shell protocol structure.\r
+\r
+ @retval EFI_SUCCESS The operation was successful.\r
+**/\r
+EFI_STATUS\r
+CleanUpShellEnvironment (\r
+ IN OUT EFI_SHELL_PROTOCOL *NewShell\r
+ );\r
+\r
/**\r
This function creates a mapping for a device path.\r
\r
/**\r
This function creates a mapping for a device path.\r
\r