diff --git a/builder/dockerfile/dispatchers.go b/builder/dockerfile/dispatchers.go index 5c9e89b94a..dd237c10be 100644 --- a/builder/dockerfile/dispatchers.go +++ b/builder/dockerfile/dispatchers.go @@ -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 diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index ac163d879c..bc6d5d3c5e 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -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"