From f3838c09d841ebdb071981e190c7579e61ee057f Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Thu, 25 Jan 2018 22:22:13 +0100 Subject: syscallcompat: hardcode maxReclen = 280 for all architectures Due to padding between entries, it is 280 even on 32-bit architectures. See https://github.com/rfjakob/gocryptfs/issues/197 for details. --- internal/syscallcompat/getdents_linux.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/syscallcompat/getdents_linux.go b/internal/syscallcompat/getdents_linux.go index aaa69ac..146517c 100644 --- a/internal/syscallcompat/getdents_linux.go +++ b/internal/syscallcompat/getdents_linux.go @@ -21,6 +21,11 @@ import ( const sizeofDirent = int(unsafe.Sizeof(syscall.Dirent{})) +// maxReclen sanity check: Reclen should never be larger than this. +// Due to padding between entries, it is 280 even on 32-bit architectures. +// See https://github.com/rfjakob/gocryptfs/issues/197 for details. +const maxReclen = 280 + // getdents wraps syscall.Getdents and converts the result to []fuse.DirEntry. func getdents(fd int) ([]fuse.DirEntry, error) { // Collect syscall result in smartBuf. @@ -53,9 +58,9 @@ func getdents(fd int) ([]fuse.DirEntry, error) { // EBADR = Invalid request descriptor return nil, syscall.EBADR } - if int(s.Reclen) > sizeofDirent { + if int(s.Reclen) > maxReclen { tlog.Warn.Printf("Getdents: corrupt entry #%d: Reclen=%d > %d. Returning EBADR", - numEntries, s.Reclen, sizeofDirent) + numEntries, s.Reclen, maxReclen) return nil, syscall.EBADR } offset += int(s.Reclen) -- cgit v1.2.3