diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c index 4443212a12..80d2dd02bc 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c @@ -314,11 +314,6 @@ ValidateAndCopyFiles( ASSERT(FileList != NULL); 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... // @@ -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);