Closed
Description
$ go version
go version devel go1.20-54182ff54a Fri Sep 9 20:29:05 2022 +0000 darwin/arm64
$ ~/src/gos/go1.18.5/bin/go version
go version go1.18.5 darwin/arm64
$ ~/src/gos/go1.18.5/bin/go run golang.org/x/vuln/cmd/govulncheck@latest .
govulncheck is an experimental tool. Share feedback at https://go.dev/s/govulncheck-feedback.
Scanning for dependencies with known vulnerabilities...
govulncheck: Packages contain errors:
/Users/dneil/src/go2/src/runtime/debuglog.go:660:15: String not declared by package unsafe
/Users/dneil/src/go2/src/runtime/proc.go:623:16: String not declared by package unsafe
/Users/dneil/src/go2/src/strings/builder.go:48:16: String not declared by package unsafe
/Users/dneil/src/go2/src/strings/builder.go:48:30: SliceData not declared by package unsafe
/Users/dneil/src/go2/src/strings/clone.go:27:16: String not declared by package unsafe
/Users/dneil/src/go2/src/os/file.go:249:27: StringData not declared by package unsafe
/Users/dneil/src/go2/src/crypto/x509/internal/macos/corefoundation.go:66:29: SliceData not declared by package unsafe
/Users/dneil/src/go2/src/crypto/x509/internal/macos/corefoundation.go:77:29: StringData not declared by package unsafe
exit status 1
$ cat main.go
package main
import "net/http"
func main() {
http.ListenAndServe(":8080", nil)
}
Not quite sure what's going on here.
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
adonovan commentedon Sep 23, 2022
This is clearly a problem in go/packages, but I can't reproduce it (either in vulncheck or in go/packages/gopackages), using the exact same two go versions on my machine.
Can you verify this by running
golang.org/x/tools/go/packages/gopackages -mode=types
instead of govulncheck, and report what it prints? That would at least eliminate govulncheck.zpavlinovic commentedon Sep 27, 2022
This is what I have.
gopackages
seems to not report errors in dependent packages, which vulncheck does. I've addedto
gopackages
. Then I get an error withallsyntax
modebut not with
types
mode.adonovan commentedon Sep 27, 2022
Ah, thanks, now it's easy to reproduce:
I should have guessed the reason from the initial report, which is obvious in hindsight: you can't use an older version of go/types than the version of Go used by the source you are trying to type-check. If you use go1.18 to build the application, then its std library is from go1.18, so its go/types won't understand newer features like unsafe.StringData. (Recall that the unsafe package is implemented directly in the type checker.)
In principle you could build the application using the go1.20 source of go/types using a go1.18 toolchain (though you might need to backport go/types to go1.18 if it happens to use new features like generics) and it would work. But we don't support that.
So the bug is that go/packages doesn't issue a clear error when it encounters Go code that is too new. I think the fix is for go/packages to specify release tags to go list that are no newer than its version of go/types. I'll file a separate issue for that.
zpavlinovic commentedon Sep 27, 2022
Thank @adonovan, this makes sense.
@neild, would the solution to this issue in govulncheck then be a good message too?
neild commentedon Sep 27, 2022
Maybe? Certainly, if the
go
tool version needs to match (or just be less than?) the version used to buildgovulncheck
, then there needs to be a good error message when this constraint is violated.gopherbot commentedon Sep 27, 2022
Change https://go.dev/cl/435356 mentions this issue:
go/packages: warn if 'go list' on PATH is too new
go/packages: issue error if 'go list' on PATH is too new
go/packages: issue error if 'go list' on PATH is too new