diff options
author | Jakob Unterwurzacher | 2019-02-17 17:05:05 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2019-02-17 17:05:05 +0100 |
commit | 19cb6d046aac92f44722c17ba9a371b08ca0be6a (patch) | |
tree | c7134052a935c75ab834786a59df9529aa8495f3 /internal/nametransform/diriv.go | |
parent | 26286a5f8cbd11557bc6e733741fbd3980f6d050 (diff) |
nametransform: reject names longer than 255 chars
Looks like we allowed creating longer names by accident.
Fix that, and add a test that verifies it.
Diffstat (limited to 'internal/nametransform/diriv.go')
-rw-r--r-- | internal/nametransform/diriv.go | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/internal/nametransform/diriv.go b/internal/nametransform/diriv.go index 09e9dd5..da33aee 100644 --- a/internal/nametransform/diriv.go +++ b/internal/nametransform/diriv.go @@ -8,8 +8,6 @@ import ( "path/filepath" "syscall" - "golang.org/x/sys/unix" - "github.com/rfjakob/gocryptfs/internal/cryptocore" "github.com/rfjakob/gocryptfs/internal/syscallcompat" "github.com/rfjakob/gocryptfs/internal/tlog" @@ -97,12 +95,17 @@ func WriteDirIVAt(dirfd int) error { // encryptAndHashName encrypts "name" and hashes it to a longname if it is // too long. -func (be *NameTransform) EncryptAndHashName(name string, iv []byte) string { +// Returns ENAMETOOLONG if "name" is longer than 255 bytes. +func (be *NameTransform) EncryptAndHashName(name string, iv []byte) (string, error) { + // Prevent the user from creating files longer than 255 chars. + if len(name) > NameMax { + return "", syscall.ENAMETOOLONG + } cName := be.EncryptName(name, iv) - if be.longNames && len(cName) > unix.NAME_MAX { - return be.HashLongName(cName) + if be.longNames && len(cName) > NameMax { + return be.HashLongName(cName), nil } - return cName + return cName, nil } // Dir is like filepath.Dir but returns "" instead of ".". |