summaryrefslogtreecommitdiff
path: root/ShellPkg
diff options
context:
space:
mode:
authorEric Dong <eric.dong@intel.com>2013-06-04 01:06:22 +0000
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>2013-06-04 01:06:22 +0000
commited053afece04120c1c62163475806d6aef3bc329 (patch)
tree3e5522fd5818751e79739d08a69f8b8febf509f5 /ShellPkg
parent7ff3b9494d2555be9342aa80cd730d5b96b8ce4c (diff)
ShellPkg: refine the logic for cp command
Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com> Reviewed-by: Erik Bjorge <Erik.c.Bjorge@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14394 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg')
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
index 4443212a1..80d2dd02b 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
@@ -315,11 +315,6 @@ ValidateAndCopyFiles(
ASSERT(DestDir != NULL);
//
- // We already verified that this was present.
- //
- ASSERT(Cwd != NULL);
-
- //
// If we are trying to copy multiple files... make sure we got a directory for the target...
//
if (EFI_ERROR(ShellIsDirectory(DestDir)) && FileList->Link.ForwardLink != FileList->Link.BackLink) {
@@ -342,7 +337,7 @@ ValidateAndCopyFiles(
NewSize = StrSize(DestDir);
NewSize += StrSize(Node->FullName);
- NewSize += StrSize(Cwd);
+ NewSize += (Cwd == NULL)? 0 : StrSize(Cwd);
if (NewSize > PathLen) {
PathLen = NewSize;
}
@@ -405,7 +400,12 @@ ValidateAndCopyFiles(
//
// simple copy of a single file
//
- StrCpy(DestPath, Cwd);
+ if (Cwd != NULL) {
+ StrCpy(DestPath, Cwd);
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);
+ return (SHELL_INVALID_PARAMETER);
+ }
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
StrCat(DestPath, L"\\");
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
@@ -424,15 +424,25 @@ ValidateAndCopyFiles(
// Check for leading slash
//
if (DestDir[0] == L'\\') {
- //
- // Copy to the root of CWD
- //
- StrCpy(DestPath, Cwd);
+ //
+ // Copy to the root of CWD
+ //
+ if (Cwd != NULL) {
+ StrCpy(DestPath, Cwd);
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);
+ return (SHELL_INVALID_PARAMETER);
+ }
while (PathRemoveLastItem(DestPath));
StrCat(DestPath, DestDir+1);
StrCat(DestPath, Node->FileName);
} else if (StrStr(DestDir, L":") == NULL) {
- StrCpy(DestPath, Cwd);
+ if (Cwd != NULL) {
+ StrCpy(DestPath, Cwd);
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);
+ return (SHELL_INVALID_PARAMETER);
+ }
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
StrCat(DestPath, L"\\");
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
@@ -562,7 +572,7 @@ ProcessValidateAndCopyFiles(
SHELL_FREE_NON_NULL(FileInfo);
ShellCloseFileMetaArg(&List);
} else {
- ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
+ ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
}
return (ShellStatus);