From cb5fe1b9bcec7cf9b5cb4ca67d48fcb7722870d5 Mon Sep 17 00:00:00 2001 From: Alberto Donato Date: Thu, 11 Jan 2024 09:02:24 +0100 Subject: [PATCH] rework filesystem function --- server/filesystem.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/server/filesystem.go b/server/filesystem.go index e8720f2..3356568 100644 --- a/server/filesystem.go +++ b/server/filesystem.go @@ -71,21 +71,20 @@ func (fs FileSystem) newFile(name string) (*File, error) { return nil, err } if !fs.AllowOutsideSymlinks { - if target, err := filepath.EvalSymlinks(absPath); target != "" { - if err != nil { - return nil, err - } - path, err := filepath.Abs(target) - if err != nil { - return nil, err - } - root, err := filepath.Abs(fs.Root) - if err != nil { - return nil, err - } - if !strings.HasPrefix(path, root) { - return nil, os.ErrPermission - } + target, err := filepath.EvalSymlinks(absPath) + if err != nil { + return nil, err + } + path, err := filepath.Abs(target) + if err != nil { + return nil, err + } + root, err := filepath.Abs(fs.Root) + if err != nil { + return nil, err + } + if !strings.HasPrefix(path, root) { + return nil, os.ErrPermission } } return NewFile(absPath, fs.HideDotFiles)