From d4a5ca9f47b1e3ca352bf66cea46293c141945db Mon Sep 17 00:00:00 2001 From: Kato Kazuyoshi Date: Fri, 11 Apr 2014 07:47:53 +0900 Subject: [PATCH] Fix utils.FollowSymlinkInScope's infinite loop bug fs_test.go doesn't finish if Docker's code is placed under a directory which has symlinks between / and the directory. For example, the below doesn't finish before the change. /home -> usr/home FollowSymlinkInScope("/home/bob/foo/bar", "/home/bob/foo") Docker-DCO-1.1-Signed-off-by: Kato Kazuyoshi (github: kzys) Upstream-commit: 0f724863468733847306f47835739f480a7fac63 Component: engine --- components/engine/utils/fs.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/engine/utils/fs.go b/components/engine/utils/fs.go index 92864e5e16..46f64903b3 100644 --- a/components/engine/utils/fs.go +++ b/components/engine/utils/fs.go @@ -62,6 +62,15 @@ func FollowSymlinkInScope(link, root string) (string, error) { prev = filepath.Clean(prev) for { + if !strings.HasPrefix(prev, root) { + // Don't resolve symlinks outside of root. For example, + // we don't have to check /home in the below. + // + // /home -> usr/home + // FollowSymlinkInScope("/home/bob/foo/bar", "/home/bob/foo") + break + } + stat, err := os.Lstat(prev) if err != nil { if os.IsNotExist(err) {