OLD | NEW |
1 // [ $GOOS != nacl ] || exit 0 # do not bother on NaCl | 1 // [ $GOOS != nacl ] || exit 0 # do not bother on NaCl |
2 // $G $D/$F.go && $L $F.$A && | 2 // $G $D/$F.go && $L $F.$A && |
3 // ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) | 3 // ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) |
4 | 4 |
5 // Copyright 2009 The Go Authors. All rights reserved. | 5 // Copyright 2009 The Go Authors. All rights reserved. |
6 // Use of this source code is governed by a BSD-style | 6 // Use of this source code is governed by a BSD-style |
7 // license that can be found in the LICENSE file. | 7 // license that can be found in the LICENSE file. |
8 | 8 |
9 package main | 9 package main |
10 | 10 |
11 import "unsafe" | 11 import "unsafe" |
12 | 12 |
13 var dummy [512<<20]byte;» // give us a big address space | 13 var dummy [512<<20]byte»// give us a big address space |
14 type T struct { | 14 type T struct { |
15 » x [256<<20] byte; | 15 » x [256<<20] byte |
16 » i int; | 16 » i int |
17 } | 17 } |
18 | 18 |
19 func main() { | 19 func main() { |
20 // the test only tests what we intend to test | 20 // the test only tests what we intend to test |
21 // if dummy starts in the first 256 MB of memory. | 21 // if dummy starts in the first 256 MB of memory. |
22 // otherwise there might not be anything mapped | 22 // otherwise there might not be anything mapped |
23 // at the address that might be accidentally | 23 // at the address that might be accidentally |
24 // dereferenced below. | 24 // dereferenced below. |
25 if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { | 25 if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { |
26 » » panic("dummy too far out"); | 26 » » panic("dummy too far out") |
27 } | 27 } |
28 | 28 |
29 // The problem here is that indexing into t with a large | 29 // The problem here is that indexing into t with a large |
30 // enough index can jump out of the unmapped section | 30 // enough index can jump out of the unmapped section |
31 // at the beginning of memory and into valid memory. | 31 // at the beginning of memory and into valid memory. |
32 // We require the pointer dereference to check. | 32 // We require the pointer dereference to check. |
33 » var t *T; | 33 » var t *T |
34 » println(t.i);» // should crash | 34 » println(t.i)» // should crash |
35 } | 35 } |
OLD | NEW |