aboutsummaryrefslogtreecommitdiff
path: root/src/reflect/value.go
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2021-10-21 23:35:05 +0700
committerCuong Manh Le <cuong.manhle.vn@gmail.com>2021-10-22 00:56:18 +0000
commit23e57e59556f42d6935b65be63b59a8b0fc0e6ad (patch)
tree52f1b45f20b88d94c8a47acd2def93cd458da042 /src/reflect/value.go
parent3beab0cd71e9e4fedba13d762ed35db04851f1be (diff)
downloadgo-23e57e59556f42d6935b65be63b59a8b0fc0e6ad.tar.gz
go-23e57e59556f42d6935b65be63b59a8b0fc0e6ad.zip
reflect: make Value.Pointer panic on bad notinheap pointers
Same as CL 350153 did for Value.Elem to panic on bad notinheap pointers. While at it, also add more tests for notinheap deref. Change-Id: Id7d9d12ad8467de5926b6a7e8f9d659fea5fedb5 Reviewed-on: https://go-review.googlesource.com/c/go/+/357630 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/reflect/value.go')
-rw-r--r--src/reflect/value.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/reflect/value.go b/src/reflect/value.go
index 7bb8ae5b97..3e723e82a4 100644
--- a/src/reflect/value.go
+++ b/src/reflect/value.go
@@ -1940,11 +1940,13 @@ func (v Value) Pointer() uintptr {
switch k {
case Ptr:
if v.typ.ptrdata == 0 {
- // Handle pointers to go:notinheap types directly,
- // so we never materialize such pointers as an
- // unsafe.Pointer. (Such pointers are always indirect.)
- // See issue 42076.
- return *(*uintptr)(v.ptr)
+ val := *(*uintptr)(v.ptr)
+ // Since it is a not-in-heap pointer, all pointers to the heap are
+ // forbidden! See comment in Value.Elem and issue #48399.
+ if !verifyNotInHeapPtr(val) {
+ panic("reflect: reflect.Value.Pointer on an invalid notinheap pointer")
+ }
+ return val
}
fallthrough
case Chan, Map, UnsafePointer: