Browse code

Fix a panic where RUN [] would be supplied.

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)

Erik Hollensbe authored on 2015/01/09 10:00:00
Showing 2 changed files
... ...
@@ -532,9 +532,13 @@ func (b *Builder) create() (*daemon.Container, error) {
532 532
 	b.TmpContainers[c.ID] = struct{}{}
533 533
 	fmt.Fprintf(b.OutStream, " ---> Running in %s\n", utils.TruncateID(c.ID))
534 534
 
535
-	// override the entry point that may have been picked up from the base image
536
-	c.Path = config.Cmd[0]
537
-	c.Args = config.Cmd[1:]
535
+	if config.Cmd != nil {
536
+		// override the entry point that may have been picked up from the base image
537
+		c.Path = config.Cmd[0]
538
+		c.Args = config.Cmd[1:]
539
+	} else {
540
+		config.Cmd = []string{}
541
+	}
538 542
 
539 543
 	return c, nil
540 544
 }
... ...
@@ -22,6 +22,25 @@ import (
22 22
 	"github.com/docker/docker/pkg/archive"
23 23
 )
24 24
 
25
+func TestBuildJSONEmptyRun(t *testing.T) {
26
+	name := "testbuildjsonemptyrun"
27
+	defer deleteImages(name)
28
+
29
+	_, err := buildImage(
30
+		name,
31
+		`
32
+    FROM busybox
33
+    RUN []
34
+    `,
35
+		true)
36
+
37
+	if err != nil {
38
+		t.Fatal("error when dealing with a RUN statement with empty JSON array")
39
+	}
40
+
41
+	logDone("build - RUN with an empty array should not panic")
42
+}
43
+
25 44
 func TestBuildEmptyWhitespace(t *testing.T) {
26 45
 	name := "testbuildemptywhitespace"
27 46
 	defer deleteImages(name)