| 1 |
// Copyright 2016 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
//go:build amd64 && (linux || darwin) |
| 6 |
|
| 7 |
package sha1_test |
| 8 |
|
| 9 |
import ( |
| 10 |
"crypto/internal/cryptotest" |
| 11 |
"crypto/sha1" |
| 12 |
"syscall" |
| 13 |
"testing" |
| 14 |
) |
| 15 |
|
| 16 |
func TestOutOfBoundsRead(t *testing.T) { |
| 17 |
cryptotest.TestAllImplementations(t, "sha1", func(t *testing.T) { |
| 18 |
const pageSize = 4 << 10 |
| 19 |
data, err := syscall.Mmap(0, 0, 2*pageSize, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE) |
| 20 |
if err != nil { |
| 21 |
panic(err) |
| 22 |
} |
| 23 |
if err := syscall.Mprotect(data[pageSize:], syscall.PROT_NONE); err != nil { |
| 24 |
panic(err) |
| 25 |
} |
| 26 |
for i := 0; i < pageSize; i++ { |
| 27 |
sha1.Sum(data[pageSize-i : pageSize]) |
| 28 |
} |
| 29 |
}) |
| 30 |
} |