Commit c7a4099b authored by Keith Randall's avatar Keith Randall Committed by Keith Randall

syscall: dup the argument to fdopendir

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 <khr@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent db0c5242
...@@ -368,10 +368,15 @@ func writelen(fd int, buf *byte, nbuf int) (n int, err error) { ...@@ -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) { func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
// Simulate Getdirentries using fdopendir/readdir_r/closedir. // Simulate Getdirentries using fdopendir/readdir_r/closedir.
const ptrSize = unsafe.Sizeof(uintptr(0)) const ptrSize = unsafe.Sizeof(uintptr(0))
d, err := fdopendir(fd) fd2, err := Dup(fd)
if err != nil { if err != nil {
return 0, err return 0, err
} }
d, err := fdopendir(fd2)
if err != nil {
Close(fd2)
return 0, err
}
defer closedir(d) defer closedir(d)
// We keep the number of records already returned in *basep. // We keep the number of records already returned in *basep.
// It's not the full required semantics, but should handle the case // It's not the full required semantics, but should handle the case
......
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