1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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

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