diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-02-22 15:44:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-22 15:44:40 -0500 |
commit | e64669cb96cbb5802ee0d5a0f1aea9638b4d9dd8 (patch) | |
tree | b365e0625c77e89c069c96853d24c0e74cdd4192 /cmd | |
parent | 613addd56f6dfccc1382de6306f92a9d16fed4d3 (diff) | |
parent | f3a8e3324f206339386b541927445926dd137ad2 (diff) | |
download | podman-e64669cb96cbb5802ee0d5a0f1aea9638b4d9dd8.tar.gz podman-e64669cb96cbb5802ee0d5a0f1aea9638b4d9dd8.tar.bz2 podman-e64669cb96cbb5802ee0d5a0f1aea9638b4d9dd8.zip |
Merge pull request #9469 from vrothberg/cp-stdout
podman cp: /dev/std{in,out} fixes
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/containers/cp.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/cmd/podman/containers/cp.go b/cmd/podman/containers/cp.go index d3b904412..7887e9539 100644 --- a/cmd/podman/containers/cp.go +++ b/cmd/podman/containers/cp.go @@ -121,7 +121,9 @@ func copyFromContainer(container string, containerPath string, hostPath string) return err } + isStdout := false if hostPath == "-" { + isStdout = true hostPath = os.Stdout.Name() } @@ -152,10 +154,16 @@ func copyFromContainer(container string, containerPath string, hostPath string) hostBaseName = filepath.Base(hostInfo.LinkTarget) } + if !isStdout { + if err := validateFileInfo(hostInfo); err != nil { + return errors.Wrap(err, "invalid destination") + } + } + reader, writer := io.Pipe() hostCopy := func() error { defer reader.Close() - if hostInfo.LinkTarget == os.Stdout.Name() { + if isStdout { _, err := io.Copy(os.Stdout, reader) return err } @@ -223,8 +231,6 @@ func copyToContainer(container string, containerPath string, hostPath string) er if hostPath == "-" { hostPath = os.Stdin.Name() isStdin = true - } else if hostPath == os.Stdin.Name() { - isStdin = true } // Make sure that host path exists. @@ -363,3 +369,12 @@ func containerParentDir(container string, containerPath string) (string, error) workDir = filepath.Join(workDir, containerPath) return filepath.Dir(workDir), nil } + +// validateFileInfo returns an error if the specified FileInfo doesn't point to +// a directory or a regular file. +func validateFileInfo(info *copy.FileInfo) error { + if info.Mode.IsDir() || info.Mode.IsRegular() { + return nil + } + return errors.Errorf("%q must be a directory or a regular file", info.LinkTarget) +} |