From 8fcda56d79d0c3652d0eb4f0317c951cfddc5b18 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Fri, 31 Oct 2014 13:56:53 -0700 Subject: [PATCH] Adds ID validation. Docker-DCO-1.1-Signed-off-by: Mrunal Patel (github: mrunalp) --- linux_factory.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/linux_factory.go b/linux_factory.go index dc998c343..4adb1bfbc 100644 --- a/linux_factory.go +++ b/linux_factory.go @@ -4,8 +4,10 @@ package libcontainer import ( "encoding/json" + "fmt" "os" "path/filepath" + "regexp" "github.com/Sirupsen/logrus" ) @@ -15,6 +17,10 @@ const ( stateFilename = "state.json" ) +var ( + idRegex = regexp.MustCompile(`^[\w_]{1,1024}$`) +) + // New returns a linux based container factory based in the root directory. func New(root string, logger *logrus.Logger) (Factory, error) { if err := os.MkdirAll(root, 0700); err != nil { @@ -37,6 +43,10 @@ type linuxFactory struct { } func (l *linuxFactory) Create(id string, config *Config) (Container, error) { + if !idRegex.MatchString(id) { + return nil, newGenericError(fmt.Errorf("Invalid id format: %s ", id), InvalidIdFormat) + } + panic("not implemented") }