mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Validate container names on creation. Fixes #3138
Move valid container name regex to the top of the file Added hyphen as a valid rune in container names. Remove group in valid container name regex.
This commit is contained in:
parent
5a89c6f6df
commit
f63cdf0260
1 changed files with 10 additions and 1 deletions
11
runtime.go
11
runtime.go
|
@ -18,6 +18,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -27,7 +28,10 @@ import (
|
||||||
// Set the max depth to the aufs restriction
|
// Set the max depth to the aufs restriction
|
||||||
const MaxImageDepth = 42
|
const MaxImageDepth = 42
|
||||||
|
|
||||||
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 {
|
type Capabilities struct {
|
||||||
MemoryLimit bool
|
MemoryLimit bool
|
||||||
|
@ -418,7 +422,12 @@ func (runtime *Runtime) Create(config *Config, name string) (*Container, []strin
|
||||||
if err != nil {
|
if err != nil {
|
||||||
name = utils.TruncateID(id)
|
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] != '/' {
|
if name[0] != '/' {
|
||||||
name = "/" + name
|
name = "/" + name
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue