1
0
mirror of https://github.com/golang/go synced 2024-11-23 22:00:11 -07:00

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
This commit is contained in:
Anton Gyllenberg 2018-10-03 01:02:06 +03:00
parent 3aa3c052e3
commit 3a70d3a427

View File

@ -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 {