-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go/version: slice bounds out of range in Lang (only at tip) #64033
Comments
This happens, because This will fix the issue: func Lang(x string) string {
v := gover.Lang(stripGo(x))
if v == "" {
return ""
}
+ if len(x) < 2+len(v) {
+ return "go" + v
+ }
return x[:2+len(v)] // "go"+v without allocation
} It does not panic for "go1", because of this: go/src/internal/gover/gover.go Lines 85 to 87 in 1cc19e5
and v.Minor is never "", because of go/src/internal/gover/gover.go Lines 103 to 112 in 1cc19e5
This might also fix the issue, but differently. This should for "go222" return "go222" instead of "go222.0". // Lang returns the Go language version. For example, Lang("1.2.3") == "1.2".
func Lang(x string) string {
v := Parse(x)
- if v.Minor == "" || v.Major == "1" && v.Minor == "0" {
+ if v.Minor == "" || v.Minor == "0" {
return v.Major
}
return v.Major + "." + v.Minor
} I am not sending a CL, because I am not sure which way this should be handled. |
CC @rsc |
Change https://go.dev/cl/541915 mentions this issue: |
For #64033 Change-Id: Iab132f86c66aa6115a349d8032e9766a14dad02e Reviewed-on: https://go-review.googlesource.com/c/go/+/541915 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com>
I believe this is fixed by https://go.dev/cl/541915. |
Looks fixed indeed on my side |
For golang#64033 Change-Id: Iab132f86c66aa6115a349d8032e9766a14dad02e Reviewed-on: https://go-review.googlesource.com/c/go/+/541915 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
It happens only on gotip, not on go 1.21
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Run https://go.dev/play/p/Y_28F1xBFWu?v=gotip
ie
version.Lang("go222")
What did you expect to see?
The program finishing and printing Hello
What did you see instead?
Found by https://github.com/catenacyber/ngolo-fuzzing with oss-fuzz :
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64002
The text was updated successfully, but these errors were encountered: