Make ':' a restricted character for file names

file names for podman load, save, export, and import cannot
contain ":" in them. It is a reserved character for parsing
filenames.

Signed-off-by: umohnani8 <umohnani@redhat.com>

Closes: #694
Approved by: rhatdan
This commit is contained in:
umohnani8
2018-04-29 17:37:51 -04:00
committed by Atomic Bot
parent d1b03f470e
commit d5d6e68592
11 changed files with 46 additions and 1 deletions

View File

@ -56,6 +56,9 @@ func exportCmd(c *cli.Context) error {
return errors.Errorf("refusing to export to terminal. Use -o flag or redirect")
}
}
if err := validateFileName(output); err != nil {
return err
}
ctr, err := runtime.LookupContainer(args[0])
if err != nil {

View File

@ -75,6 +75,10 @@ func importCmd(c *cli.Context) error {
return errors.Errorf("too many arguments. Usage TARBALL [REFERENCE]")
}
if err := validateFileName(source); err != nil {
return err
}
changes := v1.ImageConfig{}
if c.IsSet("change") {
changes, err = util.GetImageConfig(c.StringSlice("change"))

View File

@ -93,6 +93,9 @@ func loadCmd(c *cli.Context) error {
input = outFile.Name()
}
}
if err := validateFileName(input); err != nil {
return err
}
var writer io.Writer
if !c.Bool("quiet") {

View File

@ -816,3 +816,12 @@ func getLoggingPath(opts []string) string {
}
return ""
}
// validateFileName returns an error if filename contains ":"
// as it is currently not supported
func validateFileName(filename string) error {
if strings.Contains(filename, ":") {
return errors.Errorf("invalid filename (should not contain ':') %q", filename)
}
return nil
}

View File

@ -87,6 +87,9 @@ func saveCmd(c *cli.Context) error {
return errors.Errorf("refusing to save to terminal. Use -o flag or redirect")
}
}
if err := validateFileName(output); err != nil {
return err
}
var dst, manifestType string
switch c.String("format") {

View File

@ -15,6 +15,7 @@ podman export - Export container's filesystem contents as a tar archive
**podman export** exports the filesystem of a container and saves it as a tarball
on the local machine. **podman export** writes to STDOUT by default and can be
redirected to a file using the **output flag**.
Note: `:` is a restricted character and cannot be part of the file name.
**podman [GLOBAL OPTIONS]**

View File

@ -18,6 +18,7 @@ podman\-import - Import a tarball and save it as a filesystem image
and saves it as a filesystem image. Remote tarballs can be specified using a URL.
Various image instructions can be configured with the **--change** flag and
a commit message can be set using the **--message** flag.
Note: `:` is a restricted character and cannot be part of the file name.
**podman [GLOBAL OPTIONS]**

View File

@ -16,6 +16,7 @@ podman\-load - Load an image from docker archive
**podman load** copies an image from either **docker-archive** or **oci-archive** stored
on the local machine. **podman load** reads from stdin by default or a file if the **input** flag is set.
The **quiet** flag suppresses the output when set.
Note: `:` is a restricted character and cannot be part of the file name.
**podman [GLOBAL OPTIONS]**

View File

@ -18,6 +18,7 @@ podman\-save - Save an image to docker-archive or oci-archive
with oci manifest type), or **docker-dir** (directory with v2s2 manifest type) on the local machine,
default is **docker-archive**. **podman save** writes to STDOUT by default and can be redirected to a
file using the **output** flag. The **quiet** flag suppresses the output when set.
Note: `:` is a restricted character and cannot be part of the file name.
**podman [GLOBAL OPTIONS]**

View File

@ -3,9 +3,10 @@ package integration
import (
"os"
"path/filepath"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"path/filepath"
)
var _ = Describe("Podman export", func() {
@ -43,4 +44,14 @@ var _ = Describe("Podman export", func() {
err = os.Remove(outfile)
Expect(err).To(BeNil())
})
It("podman export bad filename", func() {
_, ec, cid := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
outfile := filepath.Join(podmanTest.TempDir, "container:with:colon.tar")
result := podmanTest.Podman([]string{"export", "-o", outfile, cid})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Not(Equal(0)))
})
})

View File

@ -93,4 +93,12 @@ var _ = Describe("Podman save", func() {
Expect(save.ExitCode()).To(Equal(0))
})
It("podman save bad filename", func() {
outdir := filepath.Join(podmanTest.TempDir, "save:colon")
save := podmanTest.Podman([]string{"save", "--compress", "--format", "docker-dir", "-o", outdir, ALPINE})
save.WaitWithDefaultTimeout()
Expect(save.ExitCode()).To(Not(Equal(0)))
})
})