libgocryptfs/internal/ctlsock/sanitize.go
Jakob Unterwurzacher 2758c75cae 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
2016-12-10 12:59:54 +01:00

21 lines
409 B
Go

package ctlsock
import (
"path/filepath"
)
// SanitizePath adapts filepath.Clean for FUSE paths.
// 1) It always returns a relative path
// 2) It returns "" instead of "."
// See the TestSanitizePath testcases for examples.
func SanitizePath(path string) string {
clean := filepath.Clean(path)
if clean == "." || clean == "/" {
return ""
}
if clean[0] == '/' {
clean = clean[1:]
}
return clean
}