github.com/comwrg/go/src@v0.0.0-20220319063731-c238d0440370/crypto/sha1/issue15617_test.go (about) 1 //go:build amd64 && (linux || darwin) 2 // +build amd64 3 // +build linux darwin 4 5 // Copyright 2016 The Go Authors. All rights reserved. 6 // Use of this source code is governed by a BSD-style 7 // license that can be found in the LICENSE file. 8 9 package sha1_test 10 11 import ( 12 "crypto/sha1" 13 "syscall" 14 "testing" 15 ) 16 17 func TestOutOfBoundsRead(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 }