mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #3197 from ajhager/3138-names
Validate container names on creation. Fixes #3138
This commit is contained in:
commit
a6928e70ac
1 changed files with 10 additions and 1 deletions
11
runtime.go
11
runtime.go
|
@ -18,6 +18,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -29,7 +30,10 @@ import (
|
|||
// For more information see: http://sourceforge.net/p/aufs/aufs3-standalone/ci/aufs3.12/tree/config.mk
|
||||
const MaxImageDepth = 127
|
||||
|
||||
var defaultDns = []string{"8.8.8.8", "8.8.4.4"}
|
||||
var (
|
||||
defaultDns = []string{"8.8.8.8", "8.8.4.4"}
|
||||
validContainerName = regexp.MustCompile(`^/?[a-zA-Z0-9_-]+$`)
|
||||
)
|
||||
|
||||
type Capabilities struct {
|
||||
MemoryLimit bool
|
||||
|
@ -420,7 +424,12 @@ func (runtime *Runtime) Create(config *Config, name string) (*Container, []strin
|
|||
if err != nil {
|
||||
name = utils.TruncateID(id)
|
||||
}
|
||||
} else {
|
||||
if !validContainerName.MatchString(name) {
|
||||
return nil, nil, fmt.Errorf("Invalid container name (%s), only [a-zA-Z0-9_-] are allowed", name)
|
||||
}
|
||||
}
|
||||
|
||||
if name[0] != '/' {
|
||||
name = "/" + name
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue