From: Alberto Donizetti Date: Wed, 27 Oct 2021 15:37:09 +0000 (+0200) Subject: cmd/go: don't try to print build info of non-Go binaries X-Git-Tag: go1.18beta1~302 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6e481c0b36ca484a9fe4a1de25b6def06a26b988;p=gostls13.git cmd/go: don't try to print build info of non-Go binaries On a non-nil err, buildinfo.ReadFile will always return a nil *Buildinfo. In scanFile, we need to return early if that happens. Fixes #49181 Change-Id: I354348d206ab084804937c6f922eadb61435e7b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/359154 Trust: Alberto Donizetti Run-TryBot: Alberto Donizetti Reviewed-by: Bryan C. Mills --- diff --git a/src/cmd/go/internal/version/version.go b/src/cmd/go/internal/version/version.go index febc7c638a..52502e95c6 100644 --- a/src/cmd/go/internal/version/version.go +++ b/src/cmd/go/internal/version/version.go @@ -151,6 +151,7 @@ func scanFile(file string, info fs.FileInfo, mustPrint bool) { fmt.Fprintf(os.Stderr, "%s: %v\n", file, err) } } + return } fmt.Printf("%s: %s\n", file, bi.GoVersion) diff --git a/src/cmd/go/testdata/script/go_version.txt b/src/cmd/go/testdata/script/go_version.txt new file mode 100644 index 0000000000..1a787e1b18 --- /dev/null +++ b/src/cmd/go/testdata/script/go_version.txt @@ -0,0 +1,9 @@ +# test that go version doesn't panic on non-go binaries +# See Issue #49181 + +[exec:/bin/true] cp /bin/true true +[exec:C:\windows\system32\help.exe] cp C:\windows\system32\help.exe help.exe + +go version -m . +! stdout . +! stderr .