From 3c91abce745000cdd701f1974abf6f45b991b160 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 27 Feb 2020 15:50:41 +0000 Subject: [PATCH] vfs: fix race condition caused by unlocked reading of Dir.path --- vfs/dir.go | 3 ++- vfs/file.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/vfs/dir.go b/vfs/dir.go index 75533774a..f15f19c47 100644 --- a/vfs/dir.go +++ b/vfs/dir.go @@ -476,15 +476,16 @@ func (d *Dir) Stat(name string) (node Node, err error) { func (d *Dir) ReadDirAll() (items Nodes, err error) { // fs.Debugf(d.path, "Dir.ReadDirAll") d.mu.Lock() - defer d.mu.Unlock() err = d._readDir() if err != nil { fs.Debugf(d.path, "Dir.ReadDirAll error: %v", err) + d.mu.Unlock() return nil, err } for _, item := range d.items { items = append(items, item) } + d.mu.Unlock() sort.Sort(items) // fs.Debugf(d.path, "Dir.ReadDirAll OK with %d entries", len(items)) return items, nil diff --git a/vfs/file.go b/vfs/file.go index 16f0581ff..f5e527f07 100644 --- a/vfs/file.go +++ b/vfs/file.go @@ -91,7 +91,7 @@ func (f *File) Name() (name string) { // _path returns the full path of the file // use when lock is held func (f *File) _path() string { - return path.Join(f.d.path, f.leaf) + return path.Join(f.d.Path(), f.leaf) } // Path returns the full path of the file