Skip to content

Commit

Permalink
meta: forbid empty name for dentry (#1687)
Browse files Browse the repository at this point in the history
  • Loading branch information
SandyXSD authored Apr 1, 2022
1 parent 23f7fdc commit fe910ad
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
9 changes: 9 additions & 0 deletions pkg/meta/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@ func (m *baseMeta) Mknod(ctx Context, parent Ino, name string, _type uint8, mode
if m.conf.ReadOnly {
return syscall.EROFS
}
if name == "" {
return syscall.ENOENT
}

defer timeit(time.Now())
if m.checkQuota(4<<10, 1) {
Expand Down Expand Up @@ -631,6 +634,9 @@ func (m *baseMeta) Link(ctx Context, inode, parent Ino, name string, attr *Attr)
if m.conf.ReadOnly {
return syscall.EROFS
}
if name == "" {
return syscall.ENOENT
}

defer timeit(time.Now())
parent = m.checkRoot(parent)
Expand Down Expand Up @@ -696,6 +702,9 @@ func (m *baseMeta) Rename(ctx Context, parentSrc Ino, nameSrc string, parentDst
if m.conf.ReadOnly {
return syscall.EROFS
}
if nameDst == "" {
return syscall.ENOENT
}
switch flags {
case 0, RenameNoReplace, RenameExchange:
case RenameWhiteout, RenameNoReplace | RenameWhiteout:
Expand Down
8 changes: 6 additions & 2 deletions pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -1577,9 +1577,13 @@ func (r *redisMeta) doReaddir(ctx Context, inode Ino, plus uint8, entries *[]*En
newEntries := make([]Entry, len(keys)/2)
newAttrs := make([]Attr, len(keys)/2)
for i := 0; i < len(keys); i += 2 {
typ, inode := r.parseEntry([]byte(keys[i+1]))
typ, ino := r.parseEntry([]byte(keys[i+1]))
if keys[i] == "" {
logger.Errorf("Corrupt entry with empty name: inode %d parent %d", ino, inode)
continue
}
ent := &newEntries[i/2]
ent.Inode = inode
ent.Inode = ino
ent.Name = []byte(keys[i])
ent.Attr = &newAttrs[i/2]
ent.Attr.Typ = typ
Expand Down
4 changes: 4 additions & 0 deletions pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,10 @@ func (m *dbMeta) doReaddir(ctx Context, inode Ino, plus uint8, entries *[]*Entry
return errno(err)
}
for _, n := range nodes {
if n.Name == "" {
logger.Errorf("Corrupt entry with empty name: inode %d parent %d", n.Inode, inode)
continue
}
entry := &Entry{
Inode: n.Inode,
Name: []byte(n.Name),
Expand Down
8 changes: 6 additions & 2 deletions pkg/meta/tkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -1426,9 +1426,13 @@ func (m *kvMeta) doReaddir(ctx Context, inode Ino, plus uint8, entries *[]*Entry
}
prefix := len(m.entryKey(inode, ""))
for name, buf := range vals {
typ, inode := m.parseEntry(buf)
typ, ino := m.parseEntry(buf)
if len(name) == prefix {
logger.Errorf("Corrupt entry with empty name: inode %d parent %d", ino, inode)
continue
}
*entries = append(*entries, &Entry{
Inode: inode,
Inode: ino,
Name: []byte(name)[prefix:],
Attr: &Attr{Typ: typ},
})
Expand Down

0 comments on commit fe910ad

Please sign in to comment.