Skip to content

Commit

Permalink
interp: add safeguards when searching for vendor root.
Browse files Browse the repository at this point in the history
With certain yaegi configuration on Windows, the loop in `previousRoot` can be infinite, because it fails to recognize driver letters as root.

This change adds a few more safeguards: checks path prefix earlier and checks if `filepath.Dir` produces an empty path.
  • Loading branch information
dennwc committed Mar 13, 2023
1 parent 8efc4f0 commit 166fff7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion interp/src.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ func previousRoot(filesystem fs.FS, rootPath, root string) (string, error) {
if !os.IsNotExist(err) {
return "", err
}
// stop when we reach GOPATH/src
if parent == prefix {
break
}

// stop when we reach GOPATH/src/blah
parent = filepath.Dir(parent)
Expand All @@ -259,7 +263,8 @@ func previousRoot(filesystem fs.FS, rootPath, root string) (string, error) {
// we are dealing with relative paths).
// TODO(mpl): It should probably be a critical error actually,
// as we shouldn't have gone that high up in the tree.
if parent == string(filepath.Separator) || parent == "." {
// TODO(dennwc): This partially fails on Windows, since it cannot recognize drive letters as "root".
if parent == string(filepath.Separator) || parent == "." || parent == "" {
break
}
}
Expand Down

0 comments on commit 166fff7

Please sign in to comment.