From 54f5a6674a9463fecb8656c9ffc6d80374c5868d Mon Sep 17 00:00:00 2001 From: Anton Gyllenberg Date: Tue, 2 Oct 2018 22:47:28 +0000 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 Change-Id: Iaa6a4f7b05eba30609373636e50224ae2e7d6158 GitHub-Last-Rev: 3a70d3a4277395c2dd8bb50f61b1ac3e44caee28 GitHub-Pull-Request: golang/go#27976 Reviewed-on: https://go-review.googlesource.com/c/139098 Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- 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 0921d683f0..4071341313 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 { -- 2.50.0