-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
3 changed files
with
18 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
// 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} | ||
} | ||
|
||
dest, err := vfs.Readlink(fullPath) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters