Commit 68981bf3 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

syscall: make TestGetdirentries checkptr safe

Fixes Darwin.

Updates #35092

Change-Id: I045f070c8549d00610b459e3a82cac870d9ddb54
Reviewed-on: https://go-review.googlesource.com/c/go/+/203077
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarCuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent a52c0a19
......@@ -66,7 +66,15 @@ func testGetdirentries(t *testing.T, count int) {
}
data := buf[:n]
for len(data) > 0 {
dirent := (*syscall.Dirent)(unsafe.Pointer(&data[0]))
// syscall.Getdirentries's return value may be (and usually is) much
// smaller than a syscall.Dirent, which has lots of padding for
// the name at the end. The compiler's checkptr validation doesn't like
// that. So allocate direntMem that's always big enough, and use that
// when converting to *syscall.Dirent.
var direntMem [unsafe.Sizeof(syscall.Dirent{})]byte
copy(direntMem[:], data)
dirent := (*syscall.Dirent)(unsafe.Pointer(&direntMem[0]))
data = data[dirent.Reclen:]
name := make([]byte, dirent.Namlen)
for i := 0; i < int(dirent.Namlen); i++ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment