Browse Source

POSIX: check name is too long ENAMETOOLONG

pull/2584/head
chrislu 3 years ago
parent
commit
cd1ad88f30
  1. 16
      weed/filesys/dir.go
  2. 8
      weed/filesys/dir_link.go
  3. 7
      weed/filesys/dir_rename.go
  4. 8
      weed/filesys/xattr.go

16
weed/filesys/dir.go

@ -129,6 +129,10 @@ func (dir *Dir) newDirectory(fullpath util.FullPath) fs.Node {
func (dir *Dir) Create(ctx context.Context, req *fuse.CreateRequest, func (dir *Dir) Create(ctx context.Context, req *fuse.CreateRequest,
resp *fuse.CreateResponse) (fs.Node, fs.Handle, error) { resp *fuse.CreateResponse) (fs.Node, fs.Handle, error) {
if err := checkName(req.Name); err != nil {
return nil, nil, err
}
exclusive := req.Flags&fuse.OpenExclusive != 0 exclusive := req.Flags&fuse.OpenExclusive != 0
isDirectory := req.Mode&os.ModeDir > 0 isDirectory := req.Mode&os.ModeDir > 0
@ -168,6 +172,10 @@ func (dir *Dir) Create(ctx context.Context, req *fuse.CreateRequest,
func (dir *Dir) Mknod(ctx context.Context, req *fuse.MknodRequest) (fs.Node, error) { func (dir *Dir) Mknod(ctx context.Context, req *fuse.MknodRequest) (fs.Node, error) {
if err := checkName(req.Name); err != nil {
return nil, err
}
glog.V(3).Infof("dir %s Mknod %+v", dir.FullPath(), req) glog.V(3).Infof("dir %s Mknod %+v", dir.FullPath(), req)
_, err := dir.doCreateEntry(req.Name, req.Mode, req.Uid, req.Gid, false) _, err := dir.doCreateEntry(req.Name, req.Mode, req.Uid, req.Gid, false)
@ -228,6 +236,10 @@ func (dir *Dir) doCreateEntry(name string, mode os.FileMode, uid, gid uint32, ex
func (dir *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, error) { func (dir *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, error) {
if err := checkName(req.Name); err != nil {
return nil, err
}
glog.V(4).Infof("mkdir %s: %s", dir.FullPath(), req.Name) glog.V(4).Infof("mkdir %s: %s", dir.FullPath(), req.Name)
newEntry := &filer_pb.Entry{ newEntry := &filer_pb.Entry{
@ -282,6 +294,10 @@ func (dir *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, err
func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (node fs.Node, err error) { func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (node fs.Node, err error) {
if err := checkName(req.Name); err != nil {
return nil, err
}
dirPath := util.FullPath(dir.FullPath()) dirPath := util.FullPath(dir.FullPath())
// glog.V(4).Infof("dir Lookup %s: %s by %s", dirPath, req.Name, req.Header.String()) // glog.V(4).Infof("dir Lookup %s: %s by %s", dirPath, req.Name, req.Header.String())

8
weed/filesys/dir_link.go

@ -24,6 +24,10 @@ const (
func (dir *Dir) Link(ctx context.Context, req *fuse.LinkRequest, old fs.Node) (fs.Node, error) { func (dir *Dir) Link(ctx context.Context, req *fuse.LinkRequest, old fs.Node) (fs.Node, error) {
if err := checkName(req.NewName); err != nil {
return nil, err
}
oldFile, ok := old.(*File) oldFile, ok := old.(*File)
if !ok { if !ok {
glog.Errorf("old node is not a file: %+v", old) glog.Errorf("old node is not a file: %+v", old)
@ -102,6 +106,10 @@ func (dir *Dir) Link(ctx context.Context, req *fuse.LinkRequest, old fs.Node) (f
func (dir *Dir) Symlink(ctx context.Context, req *fuse.SymlinkRequest) (fs.Node, error) { func (dir *Dir) Symlink(ctx context.Context, req *fuse.SymlinkRequest) (fs.Node, error) {
if err := checkName(req.NewName); err != nil {
return nil, err
}
glog.V(4).Infof("Symlink: %v/%v to %v", dir.FullPath(), req.NewName, req.Target) glog.V(4).Infof("Symlink: %v/%v to %v", dir.FullPath(), req.NewName, req.Target)
request := &filer_pb.CreateEntryRequest{ request := &filer_pb.CreateEntryRequest{

7
weed/filesys/dir_rename.go

@ -14,6 +14,13 @@ import (
func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirectory fs.Node) error { func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirectory fs.Node) error {
if err := checkName(req.NewName); err != nil {
return err
}
if err := checkName(req.OldName); err != nil {
return err
}
newDir := newDirectory.(*Dir) newDir := newDirectory.(*Dir)
newPath := util.NewFullPath(newDir.FullPath(), req.NewName) newPath := util.NewFullPath(newDir.FullPath(), req.NewName)

8
weed/filesys/xattr.go

@ -3,6 +3,7 @@ package filesys
import ( import (
"context" "context"
"strings" "strings"
"syscall"
"github.com/seaweedfs/fuse" "github.com/seaweedfs/fuse"
@ -143,3 +144,10 @@ func (wfs *WFS) maybeLoadEntry(dir, name string) (entry *filer_pb.Entry, err err
} }
return cachedEntry.ToProtoEntry(), cacheErr return cachedEntry.ToProtoEntry(), cacheErr
} }
func checkName(name string) error {
if len(name) >= 256 {
return syscall.ENAMETOOLONG
}
return nil
}
Loading…
Cancel
Save