aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/slice.go
diff options
context:
space:
mode:
authorcuiweixie <cuiweixie@gmail.com>2022-08-08 16:07:05 +0000
committerKeith Randall <khr@google.com>2022-08-08 16:37:49 +0000
commit52d0667e6ba69059422a138dd6589f3f697fc0db (patch)
tree991590efca972b342d0dbf565a0afa0bd0274190 /src/runtime/slice.go
parent1519729c6a1f05735fdc7a6db38dc83838783eee (diff)
downloadgo-52d0667e6ba69059422a138dd6589f3f697fc0db.tar.xz
cmd/compile,runtime: panic when unsafe.Slice param is nil and > 0
Fixes #54092 Change-Id: Ib917922ed36ee5410e5515f812737203c44f46ae GitHub-Last-Rev: dfd0c3883cf8b10479d9c5b389baa1a04c52dd34 GitHub-Pull-Request: golang/go#54107 Reviewed-on: https://go-review.googlesource.com/c/go/+/419755 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/slice.go')
-rw-r--r--src/runtime/slice.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/runtime/slice.go b/src/runtime/slice.go
index 2413a46d6a..8a0ce49fad 100644
--- a/src/runtime/slice.go
+++ b/src/runtime/slice.go
@@ -129,6 +129,12 @@ func unsafeslice(et *_type, ptr unsafe.Pointer, len int) {
panicunsafeslicelen()
}
+ if et.size == 0 {
+ if ptr == nil && len > 0 {
+ panicunsafeslicenilptr()
+ }
+ }
+
mem, overflow := math.MulUintptr(et.size, uintptr(len))
if overflow || mem > -uintptr(ptr) {
if ptr == nil {