From 3a70d3a4277395c2dd8bb50f61b1ac3e44caee28 Mon Sep 17 00:00:00 2001 From: Anton Gyllenberg Date: Wed, 3 Oct 2018 01:02:06 +0300 Subject: [PATCH] cmd/go: prevent infinite loop in QueryPackage() p = path.Dir(p) converges to either "." or "/". The current implementation of modload.QueryPackage() has a loop that terminates only on ".", not "/". This leads to the go command hanging in an infinite loop if the user manages to supply a file path starting with "/" as package path. An example of the issue is if the user (incorrectly) attempts to use an absolute directory path in an import statement within a module (import "/home/bob/myproj") and then runs go list. Fixes #27558 --- src/cmd/go/internal/modload/query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/go/internal/modload/query.go b/src/cmd/go/internal/modload/query.go index 0921d683f04..40713413131 100644 --- a/src/cmd/go/internal/modload/query.go +++ b/src/cmd/go/internal/modload/query.go @@ -221,7 +221,7 @@ func QueryPackage(path, query string, allowed func(module.Version) bool) (module } finalErr := errMissing - for p := path; p != "."; p = pathpkg.Dir(p) { + for p := path; p != "." && p != "/"; p = pathpkg.Dir(p) { info, err := Query(p, query, allowed) if err != nil { if _, ok := err.(*codehost.VCSError); ok {