Skip to content

Commit

Permalink
osfs: In BoundOS, empty baseDir disables bound checks
Browse files Browse the repository at this point in the history
This aligns the behaviour with chroot, as per use in go-git's default loader.

Signed-off-by: Paulo Gomes <[email protected]>
  • Loading branch information
pjbgf committed Aug 4, 2024
1 parent ee99c14 commit dc481f5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 1 addition & 2 deletions osfs/os_bound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions osfs/os_bound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion osfs/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
}

0 comments on commit dc481f5

Please sign in to comment.