From 2d6952e8a52168f7204fc6834e6f5d28a5b21a37 Mon Sep 17 00:00:00 2001 From: Soshi Katsuta Date: Tue, 18 Aug 2015 02:22:57 +0900 Subject: [PATCH 1/3] builder: avoid decoding "null" string in ADD, COPY and VOLUME step to nil slice Signed-off-by: Soshi Katsuta --- builder/parser/line_parsers.go | 5 +++++ builder/parser/testfiles/ADD-COPY-with-JSON/Dockerfile | 2 ++ builder/parser/testfiles/ADD-COPY-with-JSON/result | 2 ++ 3 files changed, 9 insertions(+) diff --git a/builder/parser/line_parsers.go b/builder/parser/line_parsers.go index 9bea21a958..bdfe3d5a42 100644 --- a/builder/parser/line_parsers.go +++ b/builder/parser/line_parsers.go @@ -232,6 +232,11 @@ func parseString(rest string) (*Node, map[string]bool, error) { // parseJSON converts JSON arrays to an AST. func parseJSON(rest string) (*Node, map[string]bool, error) { + rest = strings.TrimLeftFunc(rest, unicode.IsSpace) + if !strings.HasPrefix(rest, "[") { + return nil, nil, fmt.Errorf("Error parsing \"%s\" as a JSON array", rest) + } + var myJSON []interface{} if err := json.NewDecoder(strings.NewReader(rest)).Decode(&myJSON); err != nil { return nil, nil, err diff --git a/builder/parser/testfiles/ADD-COPY-with-JSON/Dockerfile b/builder/parser/testfiles/ADD-COPY-with-JSON/Dockerfile index 49372b0607..00b444cba5 100644 --- a/builder/parser/testfiles/ADD-COPY-with-JSON/Dockerfile +++ b/builder/parser/testfiles/ADD-COPY-with-JSON/Dockerfile @@ -3,6 +3,8 @@ MAINTAINER Seongyeol Lim COPY . /go/src/github.com/docker/docker ADD . / +ADD null / +COPY nullfile /tmp ADD [ "vimrc", "/tmp" ] COPY [ "bashrc", "/tmp" ] COPY [ "test file", "/tmp" ] diff --git a/builder/parser/testfiles/ADD-COPY-with-JSON/result b/builder/parser/testfiles/ADD-COPY-with-JSON/result index 86c3fef726..85aee64018 100644 --- a/builder/parser/testfiles/ADD-COPY-with-JSON/result +++ b/builder/parser/testfiles/ADD-COPY-with-JSON/result @@ -2,6 +2,8 @@ (maintainer "Seongyeol Lim ") (copy "." "/go/src/github.com/docker/docker") (add "." "/") +(add "null" "/") +(copy "nullfile" "/tmp") (add "vimrc" "/tmp") (copy "bashrc" "/tmp") (copy "test file" "/tmp") From d45fcc6c80bd67ee6a06821fd64cad029d3a756f Mon Sep 17 00:00:00 2001 From: Soshi Katsuta Date: Tue, 18 Aug 2015 02:22:57 +0900 Subject: [PATCH 2/3] integration-cli: add a integration test to avoid parsing null string in ADD, COPY and VOLUME to nil slice Signed-off-by: Soshi Katsuta --- builder/parser/line_parsers.go | 2 +- integration-cli/docker_cli_build_test.go | 27 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/builder/parser/line_parsers.go b/builder/parser/line_parsers.go index bdfe3d5a42..b28693666c 100644 --- a/builder/parser/line_parsers.go +++ b/builder/parser/line_parsers.go @@ -234,7 +234,7 @@ func parseString(rest string) (*Node, map[string]bool, error) { func parseJSON(rest string) (*Node, map[string]bool, error) { rest = strings.TrimLeftFunc(rest, unicode.IsSpace) if !strings.HasPrefix(rest, "[") { - return nil, nil, fmt.Errorf("Error parsing \"%s\" as a JSON array", rest) + return nil, nil, fmt.Errorf(`Error parsing "%s" as a JSON array`, rest) } var myJSON []interface{} diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index dad833ac42..409132c71d 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -5444,3 +5444,30 @@ func (s *DockerTrustSuite) TestBuildContextDirIsSymlink(c *check.C) { c.Fatalf("build failed with exit status %d: %s", exitStatus, out) } } + +// Issue #15634: COPY fails when path starts with "null" +func (s *DockerSuite) TestBuildNullStringInAddCopyVolume(c *check.C) { + name := "testbuildnullstringinaddcopyvolume" + + ctx, err := fakeContext(` + FROM busybox + + ADD null / + COPY nullfile / + VOLUME nullvolume + `, + map[string]string{ + "null": "test1", + "nullfile": "test2", + }, + ) + + if err != nil { + c.Fatal(err) + } + defer ctx.Close() + + if _, err := buildImageFromContext(name, ctx, true); err != nil { + c.Fatal(err) + } +} From a41f431d118291c47344b6f2599f0a8c5b272f5a Mon Sep 17 00:00:00 2001 From: Soshi Katsuta Date: Wed, 19 Aug 2015 15:17:33 +0900 Subject: [PATCH 3/3] integration-cli: use c.Assert(err, check.IsNil) instead of if err != nil Signed-off-by: Soshi Katsuta --- integration-cli/docker_cli_build_test.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 409132c71d..bf7de304c5 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -5461,13 +5461,9 @@ func (s *DockerSuite) TestBuildNullStringInAddCopyVolume(c *check.C) { "nullfile": "test2", }, ) - - if err != nil { - c.Fatal(err) - } defer ctx.Close() + c.Assert(err, check.IsNil) - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } + _, err = buildImageFromContext(name, ctx, true) + c.Assert(err, check.IsNil) }