Skip to content

path/filepath: EvalSymlinks, incorrect traversal of relative paths #30520

@jbardin

Description

@jbardin
go version go1.12 darwin/amd64
and
go version devel +820ad17303 Fri Mar 1 18:26:37 2019 +0000 darwin/amd64

Relative paths with ../ and symlinks are not correctly evaluated.

This reproduces the issue on macOS, since the $TMPDIR in/var is a symlink by default, starting from the path $HOME/foo

func main() {
	path := "../../../var/folders/"
	fmt.Println(path)
	fmt.Println(os.Getwd())
	fmt.Println(filepath.EvalSymlinks(path))
	fi, _ := os.Stat(path)
	fmt.Println(fi.Name())
}

Which outputs

$ go run eval_symlinks.go
../../../var/folders/
/Users/jbardin/foo <nil>
 lstat ../var: no such file or directory
folders

The resolution seems to depend on the number of ../ in the path, as it does work from $HOME with ../../var/folder. The errors strings also alternate the number of reported ../ depending on whether there were an odd or even number in the original path.

The behavior is the same on linux on linux with a similar directory structure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions