Skip to content

Commit 10361e7

Browse files
authored
Pass null as empty slices to getxattr on macOS (#970)
Closes #957 Signed-off-by: John Nunley <dev@notgull.net>
1 parent 5ff2b62 commit 10361e7

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/backend/libc/fs/syscalls.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,15 +2272,24 @@ pub(crate) fn lgetxattr(path: &CStr, name: &CStr, value: &mut [u8]) -> io::Resul
22722272
}
22732273

22742274
#[cfg(apple)]
2275-
unsafe {
2276-
ret_usize(c::getxattr(
2277-
path.as_ptr(),
2278-
name.as_ptr(),
2279-
value_ptr.cast::<c::c_void>(),
2280-
value.len(),
2281-
0,
2282-
c::XATTR_NOFOLLOW,
2283-
))
2275+
{
2276+
// Passing an empty to slice to getxattr leads to ERANGE on macOS. Pass null instead.
2277+
let ptr = if value.is_empty() {
2278+
core::ptr::null_mut()
2279+
} else {
2280+
value_ptr.cast::<c::c_void>()
2281+
};
2282+
2283+
unsafe {
2284+
ret_usize(c::getxattr(
2285+
path.as_ptr(),
2286+
name.as_ptr(),
2287+
ptr,
2288+
value.len(),
2289+
0,
2290+
c::XATTR_NOFOLLOW,
2291+
))
2292+
}
22842293
}
22852294
}
22862295

0 commit comments

Comments
 (0)