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 <kato.kazuyoshi@gmail.com> (github: kzys)
This commit is contained in:
Kato Kazuyoshi 2014-04-11 07:47:53 +09:00
parent e3e078ca2f
commit 0f72486346
1 changed files with 9 additions and 0 deletions

View File

@ -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) {