diff options
author | Ruiyu Ni <ruiyu.ni@intel.com> | 2016-07-13 17:38:05 +0800 |
---|---|---|
committer | Hao Wu <hao.a.wu@intel.com> | 2016-07-25 11:04:58 +0800 |
commit | 5d5094468a2ec28ce8781a9070607b770bd99295 (patch) | |
tree | 43fd6af8162c0ba7161464925a1f4f0199d23e9b | |
parent | 8d2665075081dfa51c9bc8e933fef5cbfea73c96 (diff) | |
download | edk2-platforms-5d5094468a2ec28ce8781a9070607b770bd99295.tar.xz |
ShellPkg/Cd: 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 a34b7c36621140b2da94e92373a61a549477f684)
-rw-r--r-- | ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c index 19e8e2ff9a..2e51b4cb4d 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c @@ -2,7 +2,7 @@ Main file for attrib shell level 2 function.
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
- Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 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
@@ -125,12 +125,16 @@ ShellCommandRunCd ( } else {
CwdSize = StrSize(Directory) + sizeof(CHAR16);
Cwd = AllocateZeroPool(CwdSize);
- ASSERT(Cwd!=NULL);
- StrCpyS(Cwd, StrSize(Directory)/sizeof(CHAR16)+1, Directory);
- StrCatS(Cwd, StrSize(Directory)/sizeof(CHAR16)+1, L"\\");
- Drive = GetFullyQualifiedPath(Cwd);
- PathRemoveLastItem(Drive);
- FreePool(Cwd);
+ if (Cwd == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"cd");
+ ShellStatus = SHELL_OUT_OF_RESOURCES;
+ } else {
+ StrCpyS (Cwd, StrSize (Directory) / sizeof (CHAR16) + 1, Directory);
+ StrCatS (Cwd, StrSize (Directory) / sizeof (CHAR16) + 1, L"\\");
+ Drive = GetFullyQualifiedPath (Cwd);
+ PathRemoveLastItem (Drive);
+ FreePool (Cwd);
+ }
}
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {
//
@@ -153,12 +157,16 @@ ShellCommandRunCd ( } else {
CwdSize = StrSize(Directory) + sizeof(CHAR16);
Cwd = AllocateZeroPool(CwdSize);
- ASSERT(Cwd!=NULL);
- StrCpyS(Cwd, StrSize(Directory)/sizeof(CHAR16)+1, Directory);
- StrCatS(Cwd, StrSize(Directory)/sizeof(CHAR16)+1, L"\\");
- Drive = GetFullyQualifiedPath(Cwd);
- while (PathRemoveLastItem(Drive));
- FreePool(Cwd);
+ if (Cwd == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"cd");
+ ShellStatus = SHELL_OUT_OF_RESOURCES;
+ } else {
+ StrCpyS (Cwd, StrSize (Directory) / sizeof (CHAR16) + 1, Directory);
+ StrCatS (Cwd, StrSize (Directory) / sizeof (CHAR16) + 1, L"\\");
+ Drive = GetFullyQualifiedPath (Cwd);
+ while (PathRemoveLastItem (Drive));
+ FreePool (Cwd);
+ }
}
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {
//
|