Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syscall: Getdirentries on freebsd 11 is broken #31416

Open
randall77 opened this issue Apr 11, 2019 · 3 comments

Comments

@randall77
Copy link
Contributor

commented Apr 11, 2019

Getdirentries on freebsd 11 will silently drop files from the directory listing.

It converts old, smaller records into new, bigger records. It tries to account for the size increase by calling the syscall with a smaller buffer (1/4 the size). But it also has a lower bound on the minimum size, so the syscall buffer may in fact be no smaller than the original buffer. As a result, when copying from the syscall buffer to the output buffer, there may not be room for all the listed files. The code silently drops the files that don't fit.

The patch below will at least panic in that situation. The freebsd port needs to be fixed somehow. The new test TestDirentRepeat tickles this bug.

diff --git a/src/syscall/syscall_freebsd.go b/src/syscall/syscall_freebsd.go
index 87a27b1ff7..8fdb9cb144 100644
--- a/src/syscall/syscall_freebsd.go
+++ b/src/syscall/syscall_freebsd.go
@@ -392,6 +392,11 @@ func convertFromDirents11(buf []byte, old []byte) int {
                dstPos += int(dstDirent.Reclen)
                srcPos += int(srcDirent.Reclen)
        }
+       if srcPos < len(old) {
+               // We have old entries, but can't fit them in the new entry buffer.
+               // Bad!
+               panic("leftover entries")
+       }
 
        return dstPos
 }

@paulzhol

Split off from #31403

@bcmills

This comment has been minimized.

Copy link
Member

commented Apr 11, 2019

The freebsd builders are still red, so if this can't be fixed soon, please at least send a CL to skip the test on the affected builders.

@bcmills bcmills changed the title Getdirentries on freebsd 11 is broken syscall: Getdirentries on freebsd 11 is broken Apr 11, 2019

@bcmills bcmills added the NeedsFix label Apr 11, 2019

@paulzhol paulzhol self-assigned this Apr 11, 2019

@paulzhol paulzhol added the OS-FreeBSD label Apr 11, 2019

@gopherbot

This comment has been minimized.

Copy link

commented Apr 11, 2019

Change https://golang.org/cl/171719 mentions this issue: syscall: FreeBSD Getdirentries additional buf size validation

@gopherbot

This comment has been minimized.

Copy link

commented Apr 11, 2019

Change https://golang.org/cl/171818 mentions this issue: syscall: skip DirentRepeat test on freebsd

gopherbot pushed a commit that referenced this issue Apr 16, 2019
syscall: skip DirentRepeat test on freebsd
Dirent doesn't work properly. Diable the test for now.

Update #31416

Change-Id: I34a8045598a9c303dcc754ce04da3c124f122d1a
Reviewed-on: https://go-review.googlesource.com/c/go/+/171818
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

@bcmills bcmills removed the Soon label Sep 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.