Skip to content

Commit

Permalink
Fix extract and archive from still using hard references
Browse files Browse the repository at this point in the history
  • Loading branch information
LordRalex committed Apr 23, 2024
1 parent 128d17a commit 698dcdc
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions servers/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,36 +595,15 @@ func (p *Server) GetItem(name string) (*FileData, error) {
}

func (p *Server) ArchiveItems(files []string, destination string) error {
var targets []string
for _, name := range files {
targetFile := pufferpanel.JoinPath(p.GetEnvironment().GetRootDirectory(), name)
if !pufferpanel.EnsureAccess(targetFile, p.GetEnvironment().GetRootDirectory()) {
return pufferpanel.ErrIllegalFileAccess
}
targets = append(targets, targetFile)
}

destination = pufferpanel.JoinPath(p.GetEnvironment().GetRootDirectory(), destination)
if !pufferpanel.EnsureAccess(destination, p.GetEnvironment().GetRootDirectory()) {
return pufferpanel.ErrIllegalFileAccess
}

// This may technically error out in other cases
if _, err := os.Stat(destination); !os.IsNotExist(err) {
return pufferpanel.ErrFileExists
}
return archiver.Archive(targets, destination)
return archiver.Archive(files, destination)
}

func (p *Server) Extract(source, destination string) error {
sourceFile := pufferpanel.JoinPath(p.GetEnvironment().GetRootDirectory(), source)
destinationFile := pufferpanel.JoinPath(p.GetEnvironment().GetRootDirectory(), destination)

if !pufferpanel.EnsureAccess(sourceFile, p.GetEnvironment().GetRootDirectory()) || !pufferpanel.EnsureAccess(destinationFile, p.GetEnvironment().GetRootDirectory()) {
return pufferpanel.ErrIllegalFileAccess
}

return pufferpanel.Extract(p.GetFileServer(), sourceFile, destinationFile, "*", false, nil)
return pufferpanel.Extract(p.GetFileServer(), source, destination, "*", false, nil)
}

func (p *Server) valid() bool {
Expand Down

0 comments on commit 698dcdc

Please sign in to comment.