mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Limit valid object names
Signed-off-by: Alessandro Boch <aboch@docker.com>
This commit is contained in:
parent
52bb21b7bd
commit
2682309a23
3 changed files with 6 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue