aboutsummaryrefslogtreecommitdiff
path: root/internal/nametransform/longnames.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2019-01-02 00:07:20 +0100
committerJakob Unterwurzacher2019-01-02 00:09:17 +0100
commitd99a0480f712d4fd1c2012c57a9e1c938d70c9fe (patch)
tree73c36e0cc8d971379b0cf226428840fc5a0b9340 /internal/nametransform/longnames.go
parentd5a74d2a3e1f1203fd9adeb669c122631438cb31 (diff)
nametransform: fix possible incomplete read in ReadLongNameAt
Pread() needs retry logic, so instead of implementing it ourselves, use os.File. Reported by @slackner at https://github.com/rfjakob/gocryptfs/commit/c09bf1f2284706232642431c75fa1f3d8500a9d0#r31813394
Diffstat (limited to 'internal/nametransform/longnames.go')
-rw-r--r--internal/nametransform/longnames.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/internal/nametransform/longnames.go b/internal/nametransform/longnames.go
index f0f0490..6fc080b 100644
--- a/internal/nametransform/longnames.go
+++ b/internal/nametransform/longnames.go
@@ -74,16 +74,21 @@ func IsLongContent(cName string) bool {
// Symlink-safe through Openat().
func ReadLongNameAt(dirfd int, cName string) (string, error) {
cName += LongNameSuffix
- fd, err := syscallcompat.Openat(dirfd, cName, syscall.O_NOFOLLOW, 0)
- if err != nil {
- return "", err
+ var f *os.File
+ {
+ fd, err := syscallcompat.Openat(dirfd, cName, syscall.O_NOFOLLOW, 0)
+ if err != nil {
+ return "", err
+ }
+ f = os.NewFile(uintptr(fd), "")
+ // fd runs out of scope here
}
- defer syscall.Close(fd)
+ defer f.Close()
// 256 (=255 padded to 16) bytes base64-encoded take 344 bytes: "AAAAAAA...AAA=="
lim := 344
// Allocate a bigger buffer so we see whether the file is too big
buf := make([]byte, lim+1)
- n, err := syscall.Pread(fd, buf, 0)
+ n, err := f.ReadAt(buf, 0)
if err != nil && err != io.EOF {
return "", err
}