github.com/insolar/x-crypto@v0.0.0-20191031140942-75fab8a325f6/sha1/issue15617_test.go (about)

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