From 39343b86182b4e997dc991645729ae130bd0f5f2 Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Thu, 8 Jan 2015 17:00:00 -0800 Subject: [PATCH 1/2] Fix a panic where RUN [] would be supplied. Docker-DCO-1.1-Signed-off-by: Erik Hollensbe (github: erikh) --- builder/internals.go | 10 +++++++--- integration-cli/docker_cli_build_test.go | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/builder/internals.go b/builder/internals.go index 2aa747f194..692f8f2094 100644 --- a/builder/internals.go +++ b/builder/internals.go @@ -532,9 +532,13 @@ func (b *Builder) create() (*daemon.Container, error) { b.TmpContainers[c.ID] = struct{}{} fmt.Fprintf(b.OutStream, " ---> Running in %s\n", utils.TruncateID(c.ID)) - // override the entry point that may have been picked up from the base image - c.Path = config.Cmd[0] - c.Args = config.Cmd[1:] + if config.Cmd != nil { + // override the entry point that may have been picked up from the base image + c.Path = config.Cmd[0] + c.Args = config.Cmd[1:] + } else { + config.Cmd = []string{} + } return c, nil } diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 927ab07324..ffc7594d0e 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -22,6 +22,25 @@ import ( "github.com/docker/docker/pkg/archive" ) +func TestBuildJSONEmptyRun(t *testing.T) { + name := "testbuildjsonemptyrun" + defer deleteImages(name) + + _, err := buildImage( + name, + ` + FROM busybox + RUN [] + `, + true) + + if err != nil { + t.Fatal("error when dealing with a RUN statement with empty JSON array") + } + + logDone("build - RUN with an empty array should not panic") +} + func TestBuildEmptyWhitespace(t *testing.T) { name := "testbuildemptywhitespace" defer deleteImages(name) From 3183af8b19d2adf29dd3fb80689d764353a3fe00 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Tue, 13 Jan 2015 11:13:27 -0800 Subject: [PATCH 2/2] builder: use len() > 0 instead of != nil Signed-off-by: Tibor Vass --- builder/internals.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/internals.go b/builder/internals.go index 692f8f2094..830da72725 100644 --- a/builder/internals.go +++ b/builder/internals.go @@ -532,7 +532,7 @@ func (b *Builder) create() (*daemon.Container, error) { b.TmpContainers[c.ID] = struct{}{} fmt.Fprintf(b.OutStream, " ---> Running in %s\n", utils.TruncateID(c.ID)) - if config.Cmd != nil { + if len(config.Cmd) > 0 { // override the entry point that may have been picked up from the base image c.Path = config.Cmd[0] c.Args = config.Cmd[1:]