summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libpod/options.go12
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