diff options
Diffstat (limited to 'test/nilptr')
| -rw-r--r-- | test/nilptr/arrayindex.go | 26 | ||||
| -rw-r--r-- | test/nilptr/arrayindex1.go | 31 | ||||
| -rw-r--r-- | test/nilptr/arraytoslice.go | 36 | ||||
| -rw-r--r-- | test/nilptr/arraytoslice1.go | 33 | ||||
| -rw-r--r-- | test/nilptr/arraytoslice2.go | 34 | ||||
| -rw-r--r-- | test/nilptr/slicearray.go | 32 | ||||
| -rw-r--r-- | test/nilptr/structfield.go | 34 | ||||
| -rw-r--r-- | test/nilptr/structfield1.go | 37 | ||||
| -rw-r--r-- | test/nilptr/structfield2.go | 36 | ||||
| -rw-r--r-- | test/nilptr/structfieldaddr.go | 34 |
10 files changed, 0 insertions, 333 deletions
diff --git a/test/nilptr/arrayindex.go b/test/nilptr/arrayindex.go deleted file mode 100644 index fa26532c6..000000000 --- a/test/nilptr/arrayindex.go +++ /dev/null @@ -1,26 +0,0 @@ -// $G $D/$F.go && $L $F.$A && -// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) - -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import "unsafe" - -var x byte - -func main() { - var p *[1<<30]byte = nil - x = 123 - - // The problem here is not the use of unsafe: - // it is that indexing into p[] with a large - // enough index jumps out of the unmapped section - // at the beginning of memory and into valid memory. - // Pointer offsets and array indices, if they are - // very large, need to dereference the base pointer - // to trigger a trap. - println(p[uintptr(unsafe.Pointer(&x))]) // should crash -} diff --git a/test/nilptr/arrayindex1.go b/test/nilptr/arrayindex1.go deleted file mode 100644 index 64f46e14d..000000000 --- a/test/nilptr/arrayindex1.go +++ /dev/null @@ -1,31 +0,0 @@ -// $G $D/$F.go && $L $F.$A && -// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) - -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import "unsafe" - -var dummy [512<<20]byte // give us a big address space -func main() { - // the test only tests what we intend to test - // if dummy starts in the first 256 MB of memory. - // otherwise there might not be anything mapped - // at the address that might be accidentally - // dereferenced below. - if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out") - } - - // The problem here is that indexing into p[] with a large - // enough index jumps out of the unmapped section - // at the beginning of memory and into valid memory. - // Pointer offsets and array indices, if they are - // very large, need to dereference the base pointer - // to trigger a trap. - var p *[1<<30]byte = nil - println(p[256<<20]) // very likely to be inside dummy, but should crash -} diff --git a/test/nilptr/arraytoslice.go b/test/nilptr/arraytoslice.go deleted file mode 100644 index 03879fb42..000000000 --- a/test/nilptr/arraytoslice.go +++ /dev/null @@ -1,36 +0,0 @@ -// $G $D/$F.go && $L $F.$A && -// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) - -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import "unsafe" - -func f([]byte) { - panic("unreachable") -} - -var dummy [512<<20]byte // give us a big address space -func main() { - // the test only tests what we intend to test - // if dummy starts in the first 256 MB of memory. - // otherwise there might not be anything mapped - // at the address that might be accidentally - // dereferenced below. - if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out") - } - - // The problem here is that indexing into p[] with a large - // enough index can jump out of the unmapped section - // at the beginning of memory and into valid memory. - // - // To avoid needing a check on every slice beyond the - // usual len and cap, we require the *array -> slice - // conversion to do the check. - var p *[1<<30]byte = nil - f(p[0:]) // should crash -} diff --git a/test/nilptr/arraytoslice1.go b/test/nilptr/arraytoslice1.go deleted file mode 100644 index c86070fa4..000000000 --- a/test/nilptr/arraytoslice1.go +++ /dev/null @@ -1,33 +0,0 @@ -// $G $D/$F.go && $L $F.$A && -// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) - -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import "unsafe" - -var dummy [512<<20]byte // give us a big address space -func main() { - // the test only tests what we intend to test - // if dummy starts in the first 256 MB of memory. - // otherwise there might not be anything mapped - // at the address that might be accidentally - // dereferenced below. - if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out") - } - - // The problem here is that indexing into p[] with a large - // enough index can jump out of the unmapped section - // at the beginning of memory and into valid memory. - // - // To avoid needing a check on every slice beyond the - // usual len and cap, we require the *array -> slice - // conversion to do the check. - var p *[1<<30]byte = nil - var x []byte = p[0:] // should crash - _ = x -} diff --git a/test/nilptr/arraytoslice2.go b/test/nilptr/arraytoslice2.go deleted file mode 100644 index 68ea44083..000000000 --- a/test/nilptr/arraytoslice2.go +++ /dev/null @@ -1,34 +0,0 @@ -// $G $D/$F.go && $L $F.$A && -// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) - -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import "unsafe" - -var dummy [512<<20]byte // give us a big address space -var q *[1<<30]byte -func main() { - // the test only tests what we intend to test - // if dummy starts in the first 256 MB of memory. - // otherwise there might not be anything mapped - // at the address that might be accidentally - // dereferenced below. - if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out") - } - - // The problem here is that indexing into p[] with a large - // enough index can jump out of the unmapped section - // at the beginning of memory and into valid memory. - // - // To avoid needing a check on every slice beyond the - // usual len and cap, we require the *array -> slice - // conversion to do the check. - var x []byte - var y = &x - *y = q[0:] // should crash (uses arraytoslice runtime routine) -} diff --git a/test/nilptr/slicearray.go b/test/nilptr/slicearray.go deleted file mode 100644 index 26ca42773..000000000 --- a/test/nilptr/slicearray.go +++ /dev/null @@ -1,32 +0,0 @@ -// $G $D/$F.go && $L $F.$A && -// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) - -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import "unsafe" - -var dummy [512<<20]byte // give us a big address space -func main() { - // the test only tests what we intend to test - // if dummy starts in the first 256 MB of memory. - // otherwise there might not be anything mapped - // at the address that might be accidentally - // dereferenced below. - if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out") - } - - // The problem here is that indexing into p[] with a large - // enough index can jump out of the unmapped section - // at the beginning of memory and into valid memory. - // - // To avoid needing a check on every slice beyond the - // usual len and cap, we require the slice operation - // to do the check. - var p *[1<<30]byte = nil - var _ []byte = p[10:len(p)-10] // should crash -} diff --git a/test/nilptr/structfield.go b/test/nilptr/structfield.go deleted file mode 100644 index 35196bb68..000000000 --- a/test/nilptr/structfield.go +++ /dev/null @@ -1,34 +0,0 @@ -// $G $D/$F.go && $L $F.$A && -// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) - -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import "unsafe" - -var dummy [512<<20]byte // give us a big address space -type T struct { - x [256<<20] byte - i int -} - -func main() { - // the test only tests what we intend to test - // if dummy starts in the first 256 MB of memory. - // otherwise there might not be anything mapped - // at the address that might be accidentally - // dereferenced below. - if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out") - } - - // The problem here is that indexing into t with a large - // enough index can jump out of the unmapped section - // at the beginning of memory and into valid memory. - // We require the pointer dereference to check. - var t *T - println(t.i) // should crash -} diff --git a/test/nilptr/structfield1.go b/test/nilptr/structfield1.go deleted file mode 100644 index 7c7abed1a..000000000 --- a/test/nilptr/structfield1.go +++ /dev/null @@ -1,37 +0,0 @@ -// $G $D/$F.go && $L $F.$A && -// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) - -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import "unsafe" - -var dummy [512<<20]byte // give us a big address space -type T struct { - x [256<<20] byte - i int -} - -func f() *T { - return nil -} - -func main() { - // the test only tests what we intend to test - // if dummy starts in the first 256 MB of memory. - // otherwise there might not be anything mapped - // at the address that might be accidentally - // dereferenced below. - if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out") - } - - // The problem here is that indexing into t with a large - // enough index can jump out of the unmapped section - // at the beginning of memory and into valid memory. - // We require the pointer dereference to check. - println(f().i) // should crash -} diff --git a/test/nilptr/structfield2.go b/test/nilptr/structfield2.go deleted file mode 100644 index 02a44f173..000000000 --- a/test/nilptr/structfield2.go +++ /dev/null @@ -1,36 +0,0 @@ -// $G $D/$F.go && $L $F.$A && -// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) - -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import "unsafe" - -var dummy [512<<20]byte // give us a big address space -type T struct { - x [256<<20] byte - i int -} - -var y *T -var x = &y - -func main() { - // the test only tests what we intend to test - // if dummy starts in the first 256 MB of memory. - // otherwise there might not be anything mapped - // at the address that might be accidentally - // dereferenced below. - if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out") - } - - // The problem here is that indexing into t with a large - // enough index can jump out of the unmapped section - // at the beginning of memory and into valid memory. - // We require the pointer dereference to check. - println((*x).i) // should crash -} diff --git a/test/nilptr/structfieldaddr.go b/test/nilptr/structfieldaddr.go deleted file mode 100644 index f3177bafb..000000000 --- a/test/nilptr/structfieldaddr.go +++ /dev/null @@ -1,34 +0,0 @@ -// $G $D/$F.go && $L $F.$A && -// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) - -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import "unsafe" - -var dummy [512<<20]byte // give us a big address space -type T struct { - x [256<<20] byte - i int -} - -func main() { - // the test only tests what we intend to test - // if dummy starts in the first 256 MB of memory. - // otherwise there might not be anything mapped - // at the address that might be accidentally - // dereferenced below. - if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out") - } - - // The problem here is that indexing into t with a large - // enough index can jump out of the unmapped section - // at the beginning of memory and into valid memory. - // We require the address calculation to check. - var t *T - println(&t.i) // should crash -} |
