From 517b10352f3b7e88215a44daee9de6cb227f81e3 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Tue, 24 Jun 2014 12:50:44 -0400 Subject: [PATCH 1/2] fix bug in FollowSymlinkInScope when link == root Docker-DCO-1.1-Signed-off-by: Tibor Vass (github: tiborvass) --- symlink/fs.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/symlink/fs.go b/symlink/fs.go index 257491f..32ca06b 100644 --- a/symlink/fs.go +++ b/symlink/fs.go @@ -13,8 +13,6 @@ const maxLoopCounter = 100 // FollowSymlink will follow an existing link and scope it to the root // path provided. func FollowSymlinkInScope(link, root string) (string, error) { - prev := "/" - root, err := filepath.Abs(root) if err != nil { return "", err @@ -25,10 +23,17 @@ func FollowSymlinkInScope(link, root string) (string, error) { return "", err } + if link == root { + 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) From 09930dae8fb6e23e393ddf035a046f1b243e1cab Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Tue, 24 Jun 2014 12:53:53 -0400 Subject: [PATCH 2/2] add integration test for --workdir=/ Docker-DCO-1.1-Signed-off-by: Tibor Vass (github: tiborvass) --- symlink/fs.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/symlink/fs.go b/symlink/fs.go index 32ca06b..da9c590 100644 --- a/symlink/fs.go +++ b/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)