Ensure that names are reasonable via regex

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #175
Approved by: rhatdan
This commit is contained in:
Matthew Heon 2018-01-02 14:02:52 -05:00 committed by Atomic Bot
parent 1a48c426c9
commit de6d5b75ac
1 changed files with 12 additions and 0 deletions

View File

@ -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