From 879d66e7db25d1bd1ce8c0906ceb069cdf713f62 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Thu, 24 Jun 2021 13:53:36 +0200 Subject: [v3.2] cp: do not allow dir->file copying Fix a bug in `podman-cp` to forbid copying directories to files. Previously, the directory was copied to the parent directory of the file which is wrong. Signed-off-by: Valentin Rothberg --- cmd/podman/containers/cp.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'cmd') diff --git a/cmd/podman/containers/cp.go b/cmd/podman/containers/cp.go index 27aacc6e5..0be135c91 100644 --- a/cmd/podman/containers/cp.go +++ b/cmd/podman/containers/cp.go @@ -179,6 +179,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() @@ -336,6 +340,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() -- cgit v1.2.3-54-g00ecf