From 904bf049c1626567ee28a21bde4b68ab82c5ce77 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 31 Mar 2014 19:10:19 +0000 Subject: [PATCH] Force abs paths for host volumes Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- integration-cli/docker_cli_run_test.go | 12 ++++++++++++ runtime/volumes.go | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 13959adea7fbf..8d62108fed41d 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -271,3 +271,15 @@ func TestDockerRunWithVolumesAsFiles(t *testing.T) { logDone("run - regression test for #4741 - volumes from as files") } + +// Regression test for #4830 +func TestDockerRunWithRelativePath(t *testing.T) { + runCmd := exec.Command(dockerBinary, "run", "-v", "tmp:/other-tmp", "busybox", "true") + if _, _, _, err := runCommandWithStdoutStderr(runCmd); err == nil { + t.Fatalf("relative path should result in an error") + } + + deleteAllContainers() + + logDone("run - volume with relative path") +} diff --git a/runtime/volumes.go b/runtime/volumes.go index 5ac82ef089ba3..c504644ae871b 100644 --- a/runtime/volumes.go +++ b/runtime/volumes.go @@ -172,6 +172,13 @@ func createVolumes(container *Container) error { if bindMap, exists := binds[volPath]; exists { isBindMount = true srcPath = bindMap.SrcPath + srcAbs, err := filepath.Abs(srcPath) + if err != nil { + return err + } + if srcPath != srcAbs { + return fmt.Errorf("%s should be an absolute path", srcPath) + } if strings.ToLower(bindMap.Mode) == "rw" { srcRW = true }