Skip to content

Commit dc481f5

Browse files
committed
osfs: In BoundOS, empty baseDir disables bound checks
This aligns the behaviour with chroot, as per use in go-git's default loader. Signed-off-by: Paulo Gomes <[email protected]>
1 parent ee99c14 commit dc481f5

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

osfs/os_bound.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ func (fs *BoundOS) insideBaseDir(filename string) (bool, error) {
287287
// a dir that is within the fs.baseDir, by first evaluating any symlinks
288288
// that either filename or fs.baseDir may contain.
289289
func (fs *BoundOS) insideBaseDirEval(filename string) (bool, error) {
290-
// "/" contains all others.
291-
if fs.baseDir == "/" || fs.baseDir == filename {
290+
if fs.baseDir == "/" || fs.baseDir == "" || fs.baseDir == filename {
292291
return true, nil
293292
}
294293
dir, err := filepath.EvalSymlinks(filepath.Dir(filename))

osfs/os_bound_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,10 +1133,16 @@ func TestReadDir(t *testing.T) {
11331133

11341134
func TestInsideBaseDirEval(t *testing.T) {
11351135
assert := assert.New(t)
1136+
11361137
fs := BoundOS{baseDir: "/"}
11371138
b, err := fs.insideBaseDirEval("a")
11381139
assert.True(b)
11391140
assert.Nil(err)
1141+
1142+
fs = BoundOS{baseDir: ""}
1143+
b, err = fs.insideBaseDirEval(filepath.Join("a", "b", "c"))
1144+
assert.True(b)
1145+
assert.Nil(err)
11401146
}
11411147

11421148
func TestMkdirAll(t *testing.T) {

osfs/os_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func rename(from, to string) error {
5252
return os.Rename(from, to)
5353
}
5454

55-
func umask(new int) func() {
55+
func umask(_ int) func() {
5656
return func() {
5757
}
5858
}

0 commit comments

Comments
 (0)