Commit 4367657f authored by Jakob Unterwurzacher's avatar Jakob Unterwurzacher Committed by Han-Wen Nienhuys

fuse: fix ListXAttr out of range slice

ListXAttr called with an empty buffer returns the current size of
the list but does not touch the buffer (see man 2 listxattr).

Fixes the xfstests generic/020 crash.
Fixes https://github.com/hanwen/go-fuse/issues/337 .

Add test
Co-authored-by: default avatarHan-Wen Nienhuys <hanwen@google.com>
Change-Id: I94c94bc56fdf506d2eb924b246336b787fa2976a
parent e61449e3
...@@ -124,7 +124,30 @@ func TestXAttr(t *testing.T) { ...@@ -124,7 +124,30 @@ func TestXAttr(t *testing.T) {
if err := syscall.Setxattr(tc.mntDir+"/file", attr, value, 0); err != nil { if err := syscall.Setxattr(tc.mntDir+"/file", attr, value, 0); err != nil {
t.Fatalf("Setxattr: %v", err) t.Fatalf("Setxattr: %v", err)
} }
sz, err := syscall.Getxattr(tc.mntDir+"/file", attr, buf)
sz, err := syscall.Listxattr(tc.mntDir+"/file", nil)
if err != nil {
t.Fatalf("Listxattr: %v", err)
}
buf = make([]byte, sz)
if _, err := syscall.Listxattr(tc.mntDir+"/file", buf); err != nil {
t.Fatalf("Listxattr: %v", err)
} else {
attributes := bytes.Split(buf[:sz], []byte{0})
found := false
for _, a := range attributes {
if string(a) == attr {
found = true
break
}
}
if !found {
t.Fatalf("Listxattr: %q (not found: %q", buf[:sz], attr)
}
}
sz, err = syscall.Getxattr(tc.mntDir+"/file", attr, buf)
if err != nil { if err != nil {
t.Fatalf("Getxattr: %v", err) t.Fatalf("Getxattr: %v", err)
} }
......
...@@ -271,7 +271,11 @@ func doGetXAttr(server *Server, req *request) { ...@@ -271,7 +271,11 @@ func doGetXAttr(server *Server, req *request) {
req.status = OK req.status = OK
out.Size = n out.Size = n
} else if req.status.Ok() { } else if req.status.Ok() {
// ListXAttr called with an empty buffer returns the current size of
// the list but does not touch the buffer (see man 2 listxattr).
if len(req.flatData) > 0 {
req.flatData = req.flatData[:n] req.flatData = req.flatData[:n]
}
out.Size = n out.Size = n
} else { } else {
req.flatData = req.flatData[:0] req.flatData = req.flatData[:0]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment