Browse code

[api/client] update check Dockerfile in Context

Actually determine the relative path of the Dockerfile to the context
directory. Error out if the relative path starts with "../".

Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)

Josh Hawn authored on 2015/07/28 08:09:08
Showing 1 changed files
... ...
@@ -31,7 +31,6 @@ import (
31 31
 	"github.com/docker/docker/pkg/parsers"
32 32
 	"github.com/docker/docker/pkg/progressreader"
33 33
 	"github.com/docker/docker/pkg/streamformatter"
34
-	"github.com/docker/docker/pkg/symlink"
35 34
 	"github.com/docker/docker/pkg/ulimit"
36 35
 	"github.com/docker/docker/pkg/units"
37 36
 	"github.com/docker/docker/pkg/urlutil"
... ...
@@ -340,15 +339,15 @@ func getDockerfileRelPath(givenContextDir, givenDockerfile string) (absContextDi
340 340
 		absDockerfile = filepath.Join(absContextDir, absDockerfile)
341 341
 	}
342 342
 
343
-	// Verify that 'filename' is within the build context
344
-	absDockerfile, err = symlink.FollowSymlinkInScope(absDockerfile, absContextDir)
343
+	// Evaluate symlinks in the path to the Dockerfile too.
344
+	absDockerfile, err = filepath.EvalSymlinks(absDockerfile)
345 345
 	if err != nil {
346
-		return "", "", fmt.Errorf("The Dockerfile (%s) must be within the build context (%s)", givenDockerfile, givenContextDir)
346
+		return "", "", fmt.Errorf("unable to evaluate symlinks in Dockerfile path: %v", err)
347 347
 	}
348 348
 
349 349
 	if _, err := os.Lstat(absDockerfile); err != nil {
350 350
 		if os.IsNotExist(err) {
351
-			return "", "", fmt.Errorf("Cannot locate Dockerfile: absDockerfile: %q", absDockerfile)
351
+			return "", "", fmt.Errorf("Cannot locate Dockerfile: %q", absDockerfile)
352 352
 		}
353 353
 		return "", "", fmt.Errorf("unable to stat Dockerfile: %v", err)
354 354
 	}
... ...
@@ -357,6 +356,10 @@ func getDockerfileRelPath(givenContextDir, givenDockerfile string) (absContextDi
357 357
 		return "", "", fmt.Errorf("unable to get relative Dockerfile path: %v", err)
358 358
 	}
359 359
 
360
+	if strings.HasPrefix(relDockerfile, ".."+string(filepath.Separator)) {
361
+		return "", "", fmt.Errorf("The Dockerfile (%s) must be within the build context (%s)", givenDockerfile, givenContextDir)
362
+	}
363
+
360 364
 	return absContextDir, relDockerfile, nil
361 365
 }
362 366