mirror of
https://github.com/containers/podman.git
synced 2025-06-25 20:26:51 +08:00
Merge pull request #10772 from vrothberg/fix-cp
cp: do not allow dir->file copying
This commit is contained in:
@ -177,6 +177,10 @@ func copyFromContainer(container string, containerPath string, hostPath string)
|
||||
containerTarget = filepath.Dir(containerTarget)
|
||||
}
|
||||
|
||||
if !isStdout && containerInfo.IsDir && !hostInfo.IsDir {
|
||||
return errors.New("destination must be a directory when copying a directory")
|
||||
}
|
||||
|
||||
reader, writer := io.Pipe()
|
||||
hostCopy := func() error {
|
||||
defer reader.Close()
|
||||
@ -334,6 +338,10 @@ func copyToContainer(container string, containerPath string, hostPath string) er
|
||||
stdinFile = tmpFile.Name()
|
||||
}
|
||||
|
||||
if hostInfo.IsDir && !containerInfo.IsDir {
|
||||
return errors.New("destination must be a directory when copying a directory")
|
||||
}
|
||||
|
||||
reader, writer := io.Pipe()
|
||||
hostCopy := func() error {
|
||||
defer writer.Close()
|
||||
|
@ -272,6 +272,11 @@ load helpers
|
||||
run_podman rm -f cpcontainer
|
||||
done < <(parse_table "$tests")
|
||||
|
||||
run_podman create --name cpcontainer --workdir=/srv $cpimage sleep infinity
|
||||
run_podman 125 cp $srcdir cpcontainer:/etc/os-release
|
||||
is "$output" "Error: destination must be a directory when copying a directory" "cannot copy directory to file"
|
||||
run_podman rm -f cpcontainer
|
||||
|
||||
run_podman rmi -f $cpimage
|
||||
}
|
||||
|
||||
@ -343,6 +348,10 @@ load helpers
|
||||
is "$(< $destdir$dest_fullname/containerfile1)" "${randomcontent[1]}" "$description"
|
||||
rm -rf $destdir/*
|
||||
done < <(parse_table "$tests")
|
||||
|
||||
touch $destdir/testfile
|
||||
run_podman 125 cp cpcontainer:/etc/ $destdir/testfile
|
||||
is "$output" "Error: destination must be a directory when copying a directory" "cannot copy directory to file"
|
||||
run_podman rm -f cpcontainer
|
||||
|
||||
run_podman rmi -f $cpimage
|
||||
|
Reference in New Issue
Block a user