diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index c4261a081c..9e5a90bedf 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -945,4 +945,18 @@ func TestModeHostname(t *testing.T) { deleteAllContainers() logDone("run - hostname and several network modes") -} \ No newline at end of file +} + +func TestRootWorkdir(t *testing.T) { + s, _, err := cmd(t, "run", "--workdir", "/", "busybox", "pwd") + if err != nil { + t.Fatal(s, err) + } + if s != "/\n" { + t.Fatalf("pwd returned '%s' (expected /\\n)", s) + } + + deleteAllContainers() + + logDone("run - workdir /") +} diff --git a/pkg/symlink/fs.go b/pkg/symlink/fs.go index 32ca06b780..da9c590675 100644 --- a/pkg/symlink/fs.go +++ b/pkg/symlink/fs.go @@ -27,13 +27,12 @@ func FollowSymlinkInScope(link, root string) (string, error) { return root, nil } - if !strings.HasPrefix(filepath.Dir(link), root) { return "", fmt.Errorf("%s is not within %s", link, root) } prev := "/" - + for _, p := range strings.Split(link, "/") { prev = filepath.Join(prev, p) prev = filepath.Clean(prev)