From 166fff7072e3b2389cc3326784b8fad5ed4d8da5 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Mon, 13 Mar 2023 10:20:06 +0200 Subject: [PATCH] interp: add safeguards when searching for vendor root. 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. --- interp/src.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/interp/src.go b/interp/src.go index 86f75f717..7383ce5cf 100644 --- a/interp/src.go +++ b/interp/src.go @@ -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) @@ -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 } }