-
Notifications
You must be signed in to change notification settings - Fork 18.1k
cmd/compile: expand checkptr to find conversions of smaller types into bigger #34959
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
Comments
We do this sometimes in So we'd need to check that the underlying object allocation is large enough. Just having the base type be larger is not in itself an error. |
@randall77 Yeah. I was thinking that when we convert p to *T, we just check that p and p+sizeof(T)-1 both point into the same heap object, kinda like how we do for pointer arithmetic checking |
It might also be worth recognizing |
Change https://golang.org/cl/201778 mentions this issue: |
CL 201778 can now detect the invalid conversion here:
It still doesn't detect the original example, but because in that one One solution would be to make |
This CL extends the runtime instrumentation for (*T)(ptr) to also check that the first and last bytes of *(*T)(ptr) are part of the same heap object. Updates #22218. Updates #34959. Change-Id: I2c8063fe1b7fe6e6145e41c5654cb64dd1c9dd41 Reviewed-on: https://go-review.googlesource.com/c/go/+/201778 Run-TryBot: Matthew Dempsky <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
Change https://golang.org/cl/201781 mentions this issue: |
Holy Dennis Ritchie that was quick! Amazing, thanks! |
Change https://golang.org/cl/201840 mentions this issue: |
Escaping all unsafe.Pointer conversions for -d=checkptr seems like it might be a little too aggressive to enable for -race/-msan mode, since at least some tests are written to expect unsafe.Pointer conversions to not affect escape analysis. So instead only enable that functionality behind -d=checkptr=2. Updates #22218. Updates #34959. Change-Id: I2f0a774ea5961dabec29bc5b8ebe387a1b90d27b Reviewed-on: https://go-review.googlesource.com/c/go/+/201840 Run-TryBot: Matthew Dempsky <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
Per discussion in golang-dev.
The
checkptr
dynamic analyser doesn't find bad type conversions between types where the destination type is greater than the source type. E. g.:Playground link: https://play.golang.org/p/32lWMkFPvm5.
According to @mdempsky:
The text was updated successfully, but these errors were encountered: