Skip to content

Commit 93c9922

Browse files
committed
unix: fix Getdirentries on 32-bit freebsd 12
On freebsd 12, the system call for getdirentries writes 64 bits to *basep, even on 32-bit systems. Accomodate that by providing a uint64 to the system call and copy the base to/from that uint64. The uint64 seems to be a virtual file offset, so failing if the high bits are not zero should be fine for reasonable-sized directories. Update golang/go#32498 Change-Id: I4451894aff4e353c9f009c06ad2fdd5578dfd9f8 Reviewed-on: https://go-review.googlesource.com/c/sys/+/181500 Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Tobias Klauser <[email protected]>
1 parent 1e42afe commit 93c9922

5 files changed

+20
-6
lines changed

unix/syscall_freebsd.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,21 @@ func Getdents(fd int, buf []byte) (n int, err error) {
362362

363363
func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
364364
if supportsABI(_ino64First) {
365-
return getdirentries_freebsd12(fd, buf, basep)
365+
if unsafe.Sizeof(*basep) == 8 {
366+
return getdirentries_freebsd12(fd, buf, (*uint64)(unsafe.Pointer(basep)))
367+
}
368+
// The freebsd12 syscall needs a 64-bit base. On 32-bit machines
369+
// we can't just use the basep passed in. See #32498.
370+
var base uint64 = uint64(*basep)
371+
n, err = getdirentries_freebsd12(fd, buf, &base)
372+
*basep = uintptr(base)
373+
if base>>32 != 0 {
374+
// We can't stuff the base back into a uintptr, so any
375+
// future calls would be suspect. Generate an error.
376+
// EIO is allowed by getdirentries.
377+
err = EIO
378+
}
379+
return
366380
}
367381

368382
// The old syscall entries are smaller than the new. Use 1/4 of the original
@@ -555,7 +569,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
555569
//sys Fsync(fd int) (err error)
556570
//sys Ftruncate(fd int, length int64) (err error)
557571
//sys getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error)
558-
//sys getdirentries_freebsd12(fd int, buf []byte, basep *uintptr) (n int, err error)
572+
//sys getdirentries_freebsd12(fd int, buf []byte, basep *uint64) (n int, err error)
559573
//sys Getdtablesize() (size int)
560574
//sysnb Getegid() (egid int)
561575
//sysnb Geteuid() (uid int)

unix/zsyscall_freebsd_386.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_freebsd_amd64.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_freebsd_arm.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_freebsd_arm64.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)