Skip to content

Commit 54f5a66

Browse files
antongBryan C. Mills
authored and
Bryan C. Mills
committed
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: 3a70d3a GitHub-Pull-Request: #27976 Reviewed-on: https://go-review.googlesource.com/c/139098 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
1 parent a3a69af commit 54f5a66

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/cmd/go/internal/modload/query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func QueryPackage(path, query string, allowed func(module.Version) bool) (module
221221
}
222222

223223
finalErr := errMissing
224-
for p := path; p != "."; p = pathpkg.Dir(p) {
224+
for p := path; p != "." && p != "/"; p = pathpkg.Dir(p) {
225225
info, err := Query(p, query, allowed)
226226
if err != nil {
227227
if _, ok := err.(*codehost.VCSError); ok {

0 commit comments

Comments
 (0)