mirror of
https://github.com/golang/go
synced 2024-11-24 04:00:13 -07:00
syscall: enforce minimum buffer size to call ReadDirent
freebsd and netbsd require a minimum buffer size of 1K. Note this doesn't quite fix freebsd, it has other bugs, I'll file a separate issue. Fixes #31403 Change-Id: I9d7e78f6d30859b34715afadc4b8bd3b1ecc606b Reviewed-on: https://go-review.googlesource.com/c/go/+/171757 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
3cb92fcba7
commit
770f2a17d2
@ -12,6 +12,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -79,6 +80,14 @@ func TestDirent(t *testing.T) {
|
|||||||
|
|
||||||
func TestDirentRepeat(t *testing.T) {
|
func TestDirentRepeat(t *testing.T) {
|
||||||
const N = 100
|
const N = 100
|
||||||
|
// Note: the size of the buffer is small enough that the loop
|
||||||
|
// below will need to execute multiple times. See issue #31368.
|
||||||
|
size := N * unsafe.Offsetof(syscall.Dirent{}.Name) / 4
|
||||||
|
if runtime.GOOS == "freebsd" || runtime.GOOS == "netbsd" {
|
||||||
|
if size < 1024 {
|
||||||
|
size = 1024 // DIRBLKSIZ, see issue 31403.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Make a directory containing N files
|
// Make a directory containing N files
|
||||||
d, err := ioutil.TempDir("", "direntRepeat-test")
|
d, err := ioutil.TempDir("", "direntRepeat-test")
|
||||||
@ -106,9 +115,7 @@ func TestDirentRepeat(t *testing.T) {
|
|||||||
defer syscall.Close(fd)
|
defer syscall.Close(fd)
|
||||||
var files2 []string
|
var files2 []string
|
||||||
for {
|
for {
|
||||||
// Note: the buf is small enough that this loop will need to
|
buf := make([]byte, size)
|
||||||
// execute multiple times. See issue #31368.
|
|
||||||
buf := make([]byte, N*unsafe.Offsetof(syscall.Dirent{}.Name)/4)
|
|
||||||
n, err := syscall.ReadDirent(fd, buf)
|
n, err := syscall.ReadDirent(fd, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("syscall.readdir: %v", err)
|
t.Fatalf("syscall.readdir: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user