From 66e6806fd23f6c793f9478374278ed221dea3347 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 dc998c34..4adb1bfb 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") }