X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellLevel2CommandsLib%2FCp.c;h=05f3844966a68315dd8644289a1b21c8add865c6;hb=433a21cba1a6a825b9ec07f580164b84e5d41d3a;hp=876cb9d3ef8c0cacd0e99c60e88356ed8103b5e4;hpb=0290177adf73b36bc76f888e861da5c15e21d5d4;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c index 876cb9d3ef..05f3844966 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c @@ -87,8 +87,9 @@ CopySingleFile( Response = *Resp; List = NULL; DestVolumeInfo = NULL; + ShellStatus = SHELL_SUCCESS; - ReadSize = PcdGet16(PcdShellFileOperationSize); + ReadSize = PcdGet32(PcdShellFileOperationSize); // Why bother copying a file to itself if (StrCmp(Source, Dest) == 0) { return (SHELL_SUCCESS); @@ -232,7 +233,7 @@ CopySingleFile( // Buffer = AllocateZeroPool(ReadSize); ASSERT(Buffer != NULL); - while (ReadSize == PcdGet16(PcdShellFileOperationSize) && !EFI_ERROR(Status)) { + while (ReadSize == PcdGet32(PcdShellFileOperationSize) && !EFI_ERROR(Status)) { Status = ShellReadFile(SourceHandle, &ReadSize, Buffer); Status = ShellWriteFile(DestHandle, &ReadSize, Buffer); } @@ -255,7 +256,7 @@ CopySingleFile( // // return // - return (SHELL_SUCCESS); + return ShellStatus; } /** @@ -313,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... // @@ -341,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; } @@ -404,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'\\') { @@ -423,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'\\') { @@ -537,12 +548,11 @@ ProcessValidateAndCopyFiles( { SHELL_STATUS ShellStatus; EFI_SHELL_FILE_INFO *List; - EFI_STATUS Status; EFI_FILE_INFO *FileInfo; List = NULL; - Status = ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_READ, &List); + ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_READ, &List); if (List != NULL && List->Link.ForwardLink != List->Link.BackLink) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, DestDir); ShellStatus = SHELL_INVALID_PARAMETER; @@ -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);