| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2019 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
package main |
| 8 |
|
| 9 |
type T struct { |
| 10 |
s [1]string |
| 11 |
pad [16]uintptr |
| 12 |
} |
| 13 |
|
| 14 |
//go:noinline |
| 15 |
func f(t *int, p *int) []T { |
| 16 |
var res []T |
| 17 |
for { |
| 18 |
var e *T |
| 19 |
res = append(res, *e) |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
func main() { |
| 24 |
defer func() { |
| 25 |
useStack(100) // force a stack copy |
| 26 |
// We're expecting a panic. |
| 27 |
// The bug in this issue causes a throw, which this recover() will not squash. |
| 28 |
recover() |
| 29 |
}() |
| 30 |
junk() // fill the stack with invalid pointers |
| 31 |
f(nil, nil) |
| 32 |
} |
| 33 |
|
| 34 |
func useStack(n int) { |
| 35 |
if n == 0 { |
| 36 |
return |
| 37 |
} |
| 38 |
useStack(n - 1) |
| 39 |
} |
| 40 |
|
| 41 |
//go:noinline |
| 42 |
func junk() uintptr { |
| 43 |
var a [128]uintptr // 1k of bad pointers on the stack |
| 44 |
for i := range a { |
| 45 |
a[i] = 0xaa |
| 46 |
} |
| 47 |
return a[12] |
| 48 |
} |