Commit 715fc597 authored by Dustin L. Howett's avatar Dustin L. Howett

[xattr_darwin] Safer handling for nil/missing/0-length data.

parent 18b122e7
......@@ -18,6 +18,10 @@ const (
)
func Setxattr(path, name string, data []byte, offset uint32, options int) (err error) {
if data == nil || len(data) <= 0 {
return nil
}
cpath, cattrname := C.CString(path), C.CString(name)
defer func() {
C.free(unsafe.Pointer(cpath))
......@@ -51,6 +55,10 @@ func Getxattr(path, name string, offset uint32, options int) ([]byte, error) {
return nil, err
}
if ret == 0 {
return []byte{}, nil
}
data := make([]byte, int(ret))
ret, err = C.getxattr(cpath, cattrname, unsafe.Pointer(&data[0]), C.size_t(len(data)), C.u_int32_t(offset), C.int(options))
......
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