Commit 850263fa authored by Eliot Courtney's avatar Eliot Courtney Committed by Han-Wen Nienhuys

Fix crash on listxattr syscall with NULL list argument.

parent 1f4e9748
...@@ -34,6 +34,10 @@ func listXAttr(path string) (attributes []string, err error) { ...@@ -34,6 +34,10 @@ func listXAttr(path string) (attributes []string, err error) {
sz, err = sysListxattr(path, dest) sz, err = sysListxattr(path, dest)
} }
if sz == 0 {
return nil, err
}
// -1 to drop the final empty slice. // -1 to drop the final empty slice.
dest = dest[:sz-1] dest = dest[:sz-1]
attributesBytes := bytes.Split(dest, []byte{0}) attributesBytes := bytes.Split(dest, []byte{0})
......
...@@ -103,8 +103,8 @@ func readXAttr(p, a string) (val []byte, err error) { ...@@ -103,8 +103,8 @@ func readXAttr(p, a string) (val []byte, err error) {
return getXAttr(p, a, val) return getXAttr(p, a, val)
} }
func xattrTestCase(t *testing.T, nm string) (mountPoint string, cleanup func()) { func xattrTestCase(t *testing.T, nm string, m map[string][]byte) (mountPoint string, cleanup func()) {
xfs := NewXAttrFs(nm, xattrGolden) xfs := NewXAttrFs(nm, m)
xfs.tester = t xfs.tester = t
mountPoint, err := ioutil.TempDir("", "go-fuse-xattr_test") mountPoint, err := ioutil.TempDir("", "go-fuse-xattr_test")
if err != nil { if err != nil {
...@@ -125,9 +125,25 @@ func xattrTestCase(t *testing.T, nm string) (mountPoint string, cleanup func()) ...@@ -125,9 +125,25 @@ func xattrTestCase(t *testing.T, nm string) (mountPoint string, cleanup func())
} }
} }
func TestXAttrNoAttrs(t *testing.T) {
nm := xattrFilename
mountPoint, clean := xattrTestCase(t, nm, make(map[string][]byte))
defer clean()
mounted := filepath.Join(mountPoint, nm)
attrs, err := listXAttr(mounted)
if err != nil {
t.Error("Unexpected ListXAttr error", err)
}
if len(attrs) > 0 {
t.Errorf("ListXAttr(%s) = %s, want empty slice", mounted, attrs)
}
}
func TestXAttrNoExist(t *testing.T) { func TestXAttrNoExist(t *testing.T) {
nm := xattrFilename nm := xattrFilename
mountPoint, clean := xattrTestCase(t, nm) mountPoint, clean := xattrTestCase(t, nm, xattrGolden)
defer clean() defer clean()
mounted := filepath.Join(mountPoint, nm) mounted := filepath.Join(mountPoint, nm)
...@@ -144,7 +160,7 @@ func TestXAttrNoExist(t *testing.T) { ...@@ -144,7 +160,7 @@ func TestXAttrNoExist(t *testing.T) {
func TestXAttrRead(t *testing.T) { func TestXAttrRead(t *testing.T) {
nm := xattrFilename nm := xattrFilename
mountPoint, clean := xattrTestCase(t, nm) mountPoint, clean := xattrTestCase(t, nm, xattrGolden)
defer clean() defer clean()
mounted := filepath.Join(mountPoint, nm) mounted := filepath.Join(mountPoint, nm)
......
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