From 9ea69f8a05b808b4bab81b608436a02e2f2fba09 Mon Sep 17 00:00:00 2001 From: jcarsey Date: Mon, 4 Oct 2010 16:30:40 +0000 Subject: Verify memory allocations were successful. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10909 6f19259b-4bc3-4df7-8a09-765794883524 --- ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c | 30 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c') 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; + } } } } -- cgit v1.2.3