aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2019-10-23 20:54:05 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2019-10-24 04:36:53 +0000
commit68981bf309be6143dd4cd769ffa94e9347de1fbb (patch)
treec7eb13699ed71cab877f2e692e9bc037a0d39eb4 /src
parenta52c0a199271fa0096cd3bfc7901531294d98989 (diff)
downloadgo-68981bf309be6143dd4cd769ffa94e9347de1fbb.tar.xz
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: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/syscall/getdirentries_test.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/syscall/getdirentries_test.go b/src/syscall/getdirentries_test.go
index 8505a0bb89..1cbed8d4f7 100644
--- a/src/syscall/getdirentries_test.go
+++ b/src/syscall/getdirentries_test.go
@@ -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++ {