Skip to content

Commit 11cc5a2

Browse files
committed
reflect: panic if MakeSlice is given bad len/cap arguments.
Fixes #3330. R=golang-dev, r CC=golang-dev https://golang.org/cl/5847043
1 parent 8009542 commit 11cc5a2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/pkg/reflect/value.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,15 @@ func MakeSlice(typ Type, len, cap int) Value {
16321632
if typ.Kind() != Slice {
16331633
panic("reflect.MakeSlice of non-slice type")
16341634
}
1635+
if len < 0 {
1636+
panic("reflect.MakeSlice: negative len")
1637+
}
1638+
if cap < 0 {
1639+
panic("reflect.MakeSlice: negative cap")
1640+
}
1641+
if len > cap {
1642+
panic("reflect.MakeSlice: len > cap")
1643+
}
16351644

16361645
// Declare slice so that gc can see the base pointer in it.
16371646
var x []byte

0 commit comments

Comments
 (0)