diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-01-02 14:02:52 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-01-02 19:54:45 +0000 |
commit | de6d5b75ac8baa6871991984dc8dcf9b702b8a9e (patch) | |
tree | ca67aa59ef568b5643e74fa8b7ea9c133473d4a0 /libpod | |
parent | 1a48c426c931ab7c98233afbabb21b01276136ec (diff) | |
download | podman-de6d5b75ac8baa6871991984dc8dcf9b702b8a9e.tar.gz podman-de6d5b75ac8baa6871991984dc8dcf9b702b8a9e.tar.bz2 podman-de6d5b75ac8baa6871991984dc8dcf9b702b8a9e.zip |
Ensure that names are reasonable via regex
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Closes: #175
Approved by: rhatdan
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/options.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libpod/options.go b/libpod/options.go index cbce1f767..4836e1d67 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -3,6 +3,7 @@ package libpod import ( "fmt" "path/filepath" + "regexp" "syscall" "github.com/containers/storage" @@ -15,6 +16,7 @@ var ( ctrNotImplemented = func(c *Container) error { return fmt.Errorf("NOT IMPLEMENTED") } + nameRegex = regexp.MustCompile("[a-zA-Z0-9_-]+") ) const ( @@ -390,6 +392,11 @@ func WithName(name string) CtrCreateOption { return ErrCtrFinalized } + // Check the name against a regex + if !nameRegex.MatchString(name) { + return errors.Wrapf(ErrInvalidArg, "name must match regex [a-zA-Z0-9_-]+") + } + ctr.config.Name = name return nil @@ -453,6 +460,11 @@ func WithPodName(name string) PodCreateOption { return ErrPodFinalized } + // Check the name against a regex + if !nameRegex.MatchString(name) { + return errors.Wrapf(ErrInvalidArg, "name must match regex [a-zA-Z0-9_-]+") + } + pod.name = name return nil |