From de6d5b75ac8baa6871991984dc8dcf9b702b8a9e Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Tue, 2 Jan 2018 14:02:52 -0500 Subject: Ensure that names are reasonable via regex Signed-off-by: Matthew Heon Closes: #175 Approved by: rhatdan --- libpod/options.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libpod') 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 -- cgit v1.2.3-54-g00ecf