Skip to content

Commit 09a7b25

Browse files
committed
merge branch 'pr-7'
Kir Kolyshkin (3): Ditch pkg/errors, use native error (un)wrapping go.mod: add travis-ci: update Go versions LGTM: cyphar Closes #7 #4 #3
2 parents 90b5819 + a5ef4b9 commit 09a7b25

File tree

8 files changed

+9
-537
lines changed

8 files changed

+9
-537
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
language: go
66
go:
7-
- 1.7.x
8-
- 1.8.x
7+
- 1.13.x
8+
- 1.16.x
99
- tip
1010
arch:
1111
- AMD64

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/cyphar/filepath-securejoin
2+
3+
go 1.13

join.go

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,20 @@ package securejoin
1212

1313
import (
1414
"bytes"
15+
"errors"
1516
"os"
1617
"path/filepath"
1718
"strings"
1819
"syscall"
19-
20-
"github.com/pkg/errors"
2120
)
2221

23-
// ErrSymlinkLoop is returned by SecureJoinVFS when too many symlinks have been
24-
// evaluated in attempting to securely join the two given paths.
25-
var ErrSymlinkLoop = errors.Wrap(syscall.ELOOP, "secure join")
26-
2722
// IsNotExist tells you if err is an error that implies that either the path
2823
// accessed does not exist (or path components don't exist). This is
2924
// effectively a more broad version of os.IsNotExist.
3025
func IsNotExist(err error) bool {
31-
// If it's a bone-fide ENOENT just bail.
32-
if os.IsNotExist(errors.Cause(err)) {
33-
return true
34-
}
35-
3626
// Check that it's not actually an ENOTDIR, which in some cases is a more
3727
// convoluted case of ENOENT (usually involving weird paths).
38-
var errno error
39-
switch err := errors.Cause(err).(type) {
40-
case *os.PathError:
41-
errno = err.Err
42-
case *os.LinkError:
43-
errno = err.Err
44-
case *os.SyscallError:
45-
errno = err.Err
46-
}
47-
return errno == syscall.ENOTDIR || errno == syscall.ENOENT
28+
return errors.Is(err, os.ErrNotExist) || errors.Is(err, syscall.ENOTDIR) || errors.Is(err, syscall.ENOENT)
4829
}
4930

5031
// SecureJoinVFS joins the two given path components (similar to Join) except
@@ -68,7 +49,7 @@ func SecureJoinVFS(root, unsafePath string, vfs VFS) (string, error) {
6849
n := 0
6950
for unsafePath != "" {
7051
if n > 255 {
71-
return "", ErrSymlinkLoop
52+
return "", &os.PathError{Op: "SecureJoin", Path: root + "/" + unsafePath, Err: syscall.ELOOP}
7253
}
7354

7455
// Next path component, p.

join_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func TestSymlinkLoop(t *testing.T) {
187187
{dir, "/self/././.."},
188188
} {
189189
got, err := SecureJoin(test.root, test.unsafe)
190-
if err != ErrSymlinkLoop {
190+
if !errors.Is(err, syscall.ELOOP) {
191191
t.Errorf("securejoin(%q, %q): expected ELOOP, got %v & %q", test.root, test.unsafe, err, got)
192192
continue
193193
}

vendor.conf

Lines changed: 0 additions & 1 deletion
This file was deleted.

vendor/github.com/pkg/errors/LICENSE

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)