From 2682309a23fcb2e2fe47b77022de062273015f61 Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Fri, 11 Sep 2015 11:02:16 -0700 Subject: [PATCH] Limit valid object names Signed-off-by: Alessandro Boch --- libnetwork/config/config.go | 2 +- libnetwork/config/config_test.go | 3 +++ libnetwork/controller.go | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libnetwork/config/config.go b/libnetwork/config/config.go index bb93d981b1..1935e1657b 100644 --- a/libnetwork/config/config.go +++ b/libnetwork/config/config.go @@ -109,7 +109,7 @@ func (c *Config) ProcessOptions(options ...Option) { // IsValidName validates configuration objects supported by libnetwork func IsValidName(name string) bool { - if name == "" || strings.Contains(name, ".") { + if strings.TrimSpace(name) == "" || strings.Contains(name, ".") { return false } return true diff --git a/libnetwork/config/config_test.go b/libnetwork/config/config_test.go index 0d93819545..876078687f 100644 --- a/libnetwork/config/config_test.go +++ b/libnetwork/config/config_test.go @@ -49,6 +49,9 @@ func TestValidName(t *testing.T) { if IsValidName("") { t.Fatal("Name validation succeeds for a case when it is expected to fail") } + if IsValidName(" ") { + t.Fatal("Name validation succeeds for a case when it is expected to fail") + } if IsValidName("name.with.dots") { t.Fatal("Name validation succeeds for a case when it is expected to fail") } diff --git a/libnetwork/controller.go b/libnetwork/controller.go index d84f5d4d52..a2a861feba 100644 --- a/libnetwork/controller.go +++ b/libnetwork/controller.go @@ -204,11 +204,11 @@ func (c *controller) ConfigureNetworkDriver(networkType string, options map[stri } func (c *controller) RegisterDriver(networkType string, driver driverapi.Driver, capability driverapi.Capability) error { - c.Lock() if !config.IsValidName(networkType) { - c.Unlock() return ErrInvalidName(networkType) } + + c.Lock() if _, ok := c.drivers[networkType]; ok { c.Unlock() return driverapi.ErrActiveRegistration(networkType)