Fix panic on absolute symlink

This commit is contained in:
Jakob Unterwurzacher 2015-09-08 22:53:06 +02:00
parent 28cdff5889
commit bfdbbbf8b4
2 changed files with 7 additions and 1 deletions

View File

@ -52,7 +52,6 @@ func (be *CryptFS) encryptName(plainName string) string {
cbc.CryptBlocks(bin, bin) cbc.CryptBlocks(bin, bin)
cipherName64 := base64.URLEncoding.EncodeToString(bin) cipherName64 := base64.URLEncoding.EncodeToString(bin)
return cipherName64 return cipherName64
} }
@ -70,6 +69,12 @@ func (be *CryptFS) translatePath(path string, op bool) (string, error) {
var translatedParts []string var translatedParts []string
parts := strings.Split(path, "/") parts := strings.Split(path, "/")
for _, part := range parts { for _, part := range parts {
if part == "" {
// This happens on "/foo/bar/" on the front and on the end.
// Don't panic.
translatedParts = append(translatedParts, "")
continue
}
var newPart string var newPart string
if op == ENCRYPT { if op == ENCRYPT {
newPart = be.encryptName(part) newPart = be.encryptName(part)

View File

@ -134,6 +134,7 @@ func (fs *FS) Rmdir(name string, context *fuse.Context) (code fuse.Status) {
func (fs *FS) Symlink(pointedTo string, linkName string, context *fuse.Context) (code fuse.Status) { func (fs *FS) Symlink(pointedTo string, linkName string, context *fuse.Context) (code fuse.Status) {
// TODO symlink encryption // TODO symlink encryption
cryptfs.Debug.Printf("Symlink(\"%s\", \"%s\")\n", pointedTo, linkName)
return fs.FileSystem.Symlink(fs.EncryptPath(pointedTo), fs.EncryptPath(linkName), context) return fs.FileSystem.Symlink(fs.EncryptPath(pointedTo), fs.EncryptPath(linkName), context)
} }