diff --git a/osfs/os_bound.go b/osfs/os_bound.go index 64cc3b8..3bb5255 100644 --- a/osfs/os_bound.go +++ b/osfs/os_bound.go @@ -287,8 +287,7 @@ func (fs *BoundOS) insideBaseDir(filename string) (bool, error) { // a dir that is within the fs.baseDir, by first evaluating any symlinks // that either filename or fs.baseDir may contain. func (fs *BoundOS) insideBaseDirEval(filename string) (bool, error) { - // "/" contains all others. - if fs.baseDir == "/" || fs.baseDir == filename { + if fs.baseDir == "/" || fs.baseDir == "" || fs.baseDir == filename { return true, nil } dir, err := filepath.EvalSymlinks(filepath.Dir(filename)) diff --git a/osfs/os_bound_test.go b/osfs/os_bound_test.go index d9d44d9..6ff5e89 100644 --- a/osfs/os_bound_test.go +++ b/osfs/os_bound_test.go @@ -1133,10 +1133,16 @@ func TestReadDir(t *testing.T) { func TestInsideBaseDirEval(t *testing.T) { assert := assert.New(t) + fs := BoundOS{baseDir: "/"} b, err := fs.insideBaseDirEval("a") assert.True(b) assert.Nil(err) + + fs = BoundOS{baseDir: ""} + b, err = fs.insideBaseDirEval(filepath.Join("a", "b", "c")) + assert.True(b) + assert.Nil(err) } func TestMkdirAll(t *testing.T) { diff --git a/osfs/os_windows.go b/osfs/os_windows.go index e54df74..e23cede 100644 --- a/osfs/os_windows.go +++ b/osfs/os_windows.go @@ -52,7 +52,7 @@ func rename(from, to string) error { return os.Rename(from, to) } -func umask(new int) func() { +func umask(_ int) func() { return func() { } }