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:
parent
e3e078ca2f
commit
0f72486346
|
@ -62,6 +62,15 @@ func FollowSymlinkInScope(link, root string) (string, error) {
|
||||||
prev = filepath.Clean(prev)
|
prev = filepath.Clean(prev)
|
||||||
|
|
||||||
for {
|
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)
|
stat, err := os.Lstat(prev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
|
Loading…
Reference in New Issue