summaryrefslogtreecommitdiff
path: root/internal/ctlsock/sanitize_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-12-10 12:59:54 +0100
committerJakob Unterwurzacher2016-12-10 12:59:54 +0100
commit2758c75cae2896b7f1327fe00f60a1c017c0e0d1 (patch)
tree79b3639b9341e7c88cff50b0baba003edbeca5ed /internal/ctlsock/sanitize_test.go
parent21904cd5f03f853ea6ceccbb414a5070c1f96324 (diff)
ctlsock: sanitize paths before passing them to the backend
You used to be able to crash gocryptfs by passing "/foo" of "foo/" to the ctlsock. Fixes https://github.com/rfjakob/gocryptfs/issues/66
Diffstat (limited to 'internal/ctlsock/sanitize_test.go')
-rw-r--r--internal/ctlsock/sanitize_test.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/internal/ctlsock/sanitize_test.go b/internal/ctlsock/sanitize_test.go
new file mode 100644
index 0000000..dfcb62c
--- /dev/null
+++ b/internal/ctlsock/sanitize_test.go
@@ -0,0 +1,25 @@
+package ctlsock
+
+import (
+ "testing"
+)
+
+func TestSanitizePath(t *testing.T) {
+ testCases := [][]string{
+ {"", ""},
+ {".", ""},
+ {"/", ""},
+ {"foo", "foo"},
+ {"/foo", "foo"},
+ {"foo/", "foo"},
+ {"/foo/", "foo"},
+ {"/foo/./foo", "foo/foo"},
+ {"./", ""},
+ }
+ for _, tc := range testCases {
+ res := SanitizePath(tc[0])
+ if res != tc[1] {
+ t.Errorf("%q: got %q, want %q", tc[0], res, tc[1])
+ }
+ }
+}