summaryrefslogtreecommitdiff
path: root/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
diff options
context:
space:
mode:
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2010-10-04 16:30:40 +0000
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2010-10-04 16:30:40 +0000
commit9ea69f8a05b808b4bab81b608436a02e2f2fba09 (patch)
treef07ec891e7841fec0b8570c68e1dfddfd59e2d62 /ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
parentd38a107995ef90254713dcebf8f6bddb70183a1e (diff)
downloadedk2-platforms-9ea69f8a05b808b4bab81b608436a02e2f2fba09.tar.xz
Verify memory allocations were successful.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10909 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c')
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
index 78403c2274..99680b49d9 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
@@ -186,17 +186,27 @@ ShellCommandRunCd (
// change directory on other drive letter
//
Drive = AllocateZeroPool(StrSize(Param1));
- Drive = StrCpy(Drive, Param1);
- Path = StrStr(Drive, L":");
- *(++Path) = CHAR_NULL;
- Status = gEfiShellProtocol->SetCurDir(Drive, ++Path);
+ if (Drive == NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);
+ ShellStatus = SHELL_OUT_OF_RESOURCES;
+ } else {
+ Drive = StrCpy(Drive, Param1);
+ Path = StrStr(Drive, L":");
+ *(++Path) = CHAR_NULL;
+ if (Path == Drive + StrLen(Drive)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
+ ShellStatus = SHELL_NOT_FOUND;
+ } else {
+ Status = gEfiShellProtocol->SetCurDir(Drive, ++Path);
+ }
- if (Status == EFI_NOT_FOUND) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
- Status = SHELL_NOT_FOUND;
- } else if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1);
- Status = SHELL_NOT_FOUND;
+ if (Status == EFI_NOT_FOUND) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
+ Status = SHELL_NOT_FOUND;
+ } else if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1);
+ Status = SHELL_NOT_FOUND;
+ }
}
}
}