Skip to content

Commit

Permalink
request server: fix symlink handling for relative links
Browse files Browse the repository at this point in the history
  • Loading branch information
georgmu authored and drakkan committed Sep 30, 2022
1 parent 3aa4378 commit e8c89af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions request-example.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ func (fs *root) exists(path string) bool {
return err != os.ErrNotExist
}

func (fs *root) fetch(path string) (*memFile, error) {
file, err := fs.lfetch(path)
func (fs *root) fetch(pathname string) (*memFile, error) {
file, err := fs.lfetch(pathname)
if err != nil {
return nil, err
}
Expand All @@ -537,7 +537,12 @@ func (fs *root) fetch(path string) (*memFile, error) {
return nil, errTooManySymlinks
}

file, err = fs.lfetch(file.symlink)
linkTarget := file.symlink
if !path.IsAbs(linkTarget) {
linkTarget = path.Join(path.Dir(file.name), linkTarget)
}

file, err = fs.lfetch(linkTarget)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func requestFromPacket(ctx context.Context, pkt hasPath, baseDir string) *Reques
// NOTE: given a POSIX compliant signature: symlink(target, linkpath string)
// this makes Request.Target the linkpath, and Request.Filepath the target.
request.Target = cleanPathWithBase(baseDir, p.Linkpath)
request.Filepath = p.Targetpath
case *sshFxpExtendedPacketHardlink:
request.Target = cleanPathWithBase(baseDir, p.Newpath)
}
Expand Down

0 comments on commit e8c89af

Please sign in to comment.