aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/cgocheck.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2016-05-18 13:19:24 -0700
committerIan Lance Taylor <iant@golang.org>2016-05-18 23:39:06 +0000
commit538537a28dc956f069b83e3f1966683901205331 (patch)
treeda450c0aab09599db5fd909227478a38221bfdb7 /src/runtime/cgocheck.go
parentebbe4f8db76b947663cc535602054c84b01b080d (diff)
downloadgo-538537a28dc956f069b83e3f1966683901205331.tar.gz
go-538537a28dc956f069b83e3f1966683901205331.zip
runtime: check only up to ptrdata bytes for pointers
Fixes #14508. Change-Id: I237d0c5a79a73e6c97bdb2077d8ede613128b978 Reviewed-on: https://go-review.googlesource.com/23224 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/cgocheck.go')
-rw-r--r--src/runtime/cgocheck.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/runtime/cgocheck.go b/src/runtime/cgocheck.go
index d85d5fe5a8..2d064145a4 100644
--- a/src/runtime/cgocheck.go
+++ b/src/runtime/cgocheck.go
@@ -94,6 +94,14 @@ func cgoCheckSliceCopy(typ *_type, dst, src slice, n int) {
//go:nosplit
//go:nowritebarrier
func cgoCheckTypedBlock(typ *_type, src unsafe.Pointer, off, size uintptr) {
+ // Anything past typ.ptrdata is not a pointer.
+ if typ.ptrdata <= off {
+ return
+ }
+ if ptrdataSize := typ.ptrdata - off; size > ptrdataSize {
+ size = ptrdataSize
+ }
+
if typ.kind&kindGCProg == 0 {
cgoCheckBits(src, typ.gcdata, off, size)
return
@@ -184,7 +192,7 @@ func cgoCheckBits(src unsafe.Pointer, gcbits *byte, off, size uintptr) {
// cgoCheckUsingType is like cgoCheckTypedBlock, but is a last ditch
// fall back to look for pointers in src using the type information.
-// We only this when looking at a value on the stack when the type
+// We only use this when looking at a value on the stack when the type
// uses a GC program, because otherwise it's more efficient to use the
// GC bits. This is called on the system stack.
//go:nowritebarrier
@@ -193,6 +201,15 @@ func cgoCheckUsingType(typ *_type, src unsafe.Pointer, off, size uintptr) {
if typ.kind&kindNoPointers != 0 {
return
}
+
+ // Anything past typ.ptrdata is not a pointer.
+ if typ.ptrdata <= off {
+ return
+ }
+ if ptrdataSize := typ.ptrdata - off; size > ptrdataSize {
+ size = ptrdataSize
+ }
+
if typ.kind&kindGCProg == 0 {
cgoCheckBits(src, typ.gcdata, off, size)
return