Skip to content

Commit

Permalink
syscall: dup the argument to fdopendir
Browse files Browse the repository at this point in the history
fdopendir takes ownership of its file descriptor argument.
Getdirentries shouldn't do that, so dup the file descriptor
before passing to fdopendir.

Fixes #31269

Change-Id: Ie36be8fd6c59eb339dcc9f40228d4191fc1e5850
Reviewed-on: https://go-review.googlesource.com/c/go/+/170698
Run-TryBot: Keith Randall <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
randall77 committed Apr 5, 2019
1 parent db0c524 commit c7a4099
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/syscall/syscall_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,15 @@ func writelen(fd int, buf *byte, nbuf int) (n int, err error) {
func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
// Simulate Getdirentries using fdopendir/readdir_r/closedir.
const ptrSize = unsafe.Sizeof(uintptr(0))
d, err := fdopendir(fd)
fd2, err := Dup(fd)
if err != nil {
return 0, err
}
d, err := fdopendir(fd2)
if err != nil {
Close(fd2)
return 0, err
}
defer closedir(d)
// We keep the number of records already returned in *basep.
// It's not the full required semantics, but should handle the case
Expand Down

0 comments on commit c7a4099

Please sign in to comment.