-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
Go modules mean adding dependencies is less painful than it was when we started this project, and we will need some syscalls from unix for implementing a safe MkdirAll. Signed-off-by: Aleksa Sarai <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/cyphar/filepath-securejoin | ||
|
||
go 1.13 | ||
|
||
require golang.org/x/sys v0.21.0 // indirect |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= | ||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,8 @@ import ( | |
"os" | ||
"path/filepath" | ||
"strings" | ||
"syscall" | ||
|
||
"golang.org/x/sys/unix" | ||
Check failure on line 19 in join.go GitHub Actions / test (ubuntu-latest, 1.14)
Check failure on line 19 in join.go GitHub Actions / test (windows-latest, 1.14)
|
||
) | ||
|
||
const maxSymlinkLimit = 255 | ||
|
@@ -26,7 +27,7 @@ const maxSymlinkLimit = 255 | |
func IsNotExist(err error) bool { | ||
// Check that it's not actually an ENOTDIR, which in some cases is a more | ||
// convoluted case of ENOENT (usually involving weird paths). | ||
return errors.Is(err, os.ErrNotExist) || errors.Is(err, syscall.ENOTDIR) || errors.Is(err, syscall.ENOENT) | ||
return errors.Is(err, os.ErrNotExist) || errors.Is(err, unix.ENOTDIR) || errors.Is(err, unix.ENOENT) | ||
Check failure on line 30 in join.go GitHub Actions / test (windows-latest, 1.21)
Check failure on line 30 in join.go GitHub Actions / test (windows-latest, 1.21)
Check failure on line 30 in join.go GitHub Actions / test (windows-latest, 1.22)
Check failure on line 30 in join.go GitHub Actions / test (windows-latest, 1.22)
Check failure on line 30 in join.go GitHub Actions / test (windows-latest, ^1)
|
||
} | ||
|
||
// SecureJoinVFS joins the two given path components (similar to Join) except | ||
|
@@ -97,7 +98,7 @@ func SecureJoinVFS(root, unsafePath string, vfs VFS) (string, error) { | |
// to the yet-unparsed path. | ||
linksWalked++ | ||
if linksWalked > maxSymlinkLimit { | ||
return "", &os.PathError{Op: "SecureJoin", Path: root + string(filepath.Separator) + unsafePath, Err: syscall.ELOOP} | ||
return "", &os.PathError{Op: "SecureJoin", Path: root + string(filepath.Separator) + unsafePath, Err: unix.ELOOP} | ||
Check failure on line 101 in join.go GitHub Actions / test (windows-latest, 1.21)
Check failure on line 101 in join.go GitHub Actions / test (windows-latest, 1.22)
|
||
} | ||
|
||
dest, err := vfs.Readlink(fullPath) | ||
|