Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
further fix for absolute paths (#110)
Browse files Browse the repository at this point in the history
we removed the explicit rejection, but still expanded the path in a way
that's unsuitable for paths that are already absolute.
  • Loading branch information
dbaggerman authored and ojkelly committed Sep 7, 2018
1 parent f7d1399 commit 567bb2a
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions internal/core/object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ func NewFilesystemStore(basedir string) *FileSystemStore {
}

func (fs *FileSystemStore) Get(path string, subpath ...string) ([]byte, error) {
var keys []string

// go doesn't allow passing mixed values and variadic arrays so we need to
// collapse it to a single array first
keys := append([]string{fs.basedir, path}, subpath...)
if filepath.IsAbs(path) {
keys = append([]string{path}, subpath...)
} else {
keys = append([]string{fs.basedir, path}, subpath...)
}

objectPath := filepath.Join(keys...)

data, err := ioutil.ReadFile(objectPath)
Expand All @@ -44,13 +51,16 @@ func (fs *FileSystemStore) Get(path string, subpath ...string) ([]byte, error) {
}

func (fs *FileSystemStore) Put(data []byte, path string, subpath ...string) error {
if filepath.IsAbs(path) {
return fmt.Errorf("put object: only relative paths allowed")
}
var keys []string

// go doesn't allow passing mixed values and variadic arrays so we need to
// collapse it to a single array first
keys := append([]string{fs.basedir, path}, subpath...)
if filepath.IsAbs(path) {
keys = append([]string{path}, subpath...)
} else {
keys = append([]string{fs.basedir, path}, subpath...)
}

objectPath := filepath.Join(keys...)

// Transparently create directories when required, to be
Expand Down

0 comments on commit 567bb2a

Please sign in to comment.