1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Don't allow empty env names

Closes: #25281

Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
Doug Davis 2016-08-01 09:38:05 -07:00
parent befb456832
commit e72c0137af
2 changed files with 50 additions and 0 deletions

View file

@ -66,6 +66,11 @@ func env(b *Builder, args []string, attributes map[string]bool, original string)
for j := 0; j < len(args); j++ {
// name ==> args[j]
// value ==> args[j+1]
if len(args[j]) == 0 {
return fmt.Errorf("ENV names can not be blank")
}
newVar := args[j] + "=" + args[j+1] + ""
commitStr += " " + newVar
@ -129,6 +134,11 @@ func label(b *Builder, args []string, attributes map[string]bool, original strin
for j := 0; j < len(args); j++ {
// name ==> args[j]
// value ==> args[j+1]
if len(args[j]) == 0 {
return fmt.Errorf("LABEL names can not be blank")
}
newVar := args[j] + "=" + args[j+1] + ""
commitStr += " " + newVar
@ -696,6 +706,10 @@ func arg(b *Builder, args []string, attributes map[string]bool, original string)
// name-value pair). If possible, it will be good to harmonize the two.
if strings.Contains(arg, "=") {
parts := strings.SplitN(arg, "=", 2)
if len(parts[0]) == 0 {
return fmt.Errorf("ARG names can not be blank")
}
name = parts[0]
value = parts[1]
hasDefault = true

View file

@ -2020,6 +2020,42 @@ func (s *DockerSuite) TestBuildRelativeCopy(c *check.C) {
}
}
func (s *DockerSuite) TestBuildBlankName(c *check.C) {
name := "testbuildblankname"
_, _, stderr, err := buildImageWithStdoutStderr(name,
`FROM busybox
ENV =`,
true)
if err == nil {
c.Fatal("Build was supposed to fail but didn't")
}
if !strings.Contains(stderr, "ENV names can not be blank") {
c.Fatalf("Missing error message, got: %s", stderr)
}
_, _, stderr, err = buildImageWithStdoutStderr(name,
`FROM busybox
LABEL =`,
true)
if err == nil {
c.Fatal("Build was supposed to fail but didn't")
}
if !strings.Contains(stderr, "LABEL names can not be blank") {
c.Fatalf("Missing error message, got: %s", stderr)
}
_, _, stderr, err = buildImageWithStdoutStderr(name,
`FROM busybox
ARG =foo`,
true)
if err == nil {
c.Fatal("Build was supposed to fail but didn't")
}
if !strings.Contains(stderr, "ARG names can not be blank") {
c.Fatalf("Missing error message, got: %s", stderr)
}
}
func (s *DockerSuite) TestBuildEnv(c *check.C) {
testRequires(c, DaemonIsLinux) // ENV expansion is different in Windows
name := "testbuildenv"