Skip to content

Commit

Permalink
Pass null as empty slices to getxattr on macOS (#970)
Browse files Browse the repository at this point in the history
Closes #957

Signed-off-by: John Nunley <dev@notgull.net>
  • Loading branch information
notgull authored Dec 18, 2023
1 parent 5ff2b62 commit 10361e7
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2272,15 +2272,24 @@ pub(crate) fn lgetxattr(path: &CStr, name: &CStr, value: &mut [u8]) -> io::Resul
}

#[cfg(apple)]
unsafe {
ret_usize(c::getxattr(
path.as_ptr(),
name.as_ptr(),
value_ptr.cast::<c::c_void>(),
value.len(),
0,
c::XATTR_NOFOLLOW,
))
{
// Passing an empty to slice to getxattr leads to ERANGE on macOS. Pass null instead.
let ptr = if value.is_empty() {
core::ptr::null_mut()
} else {
value_ptr.cast::<c::c_void>()
};

unsafe {
ret_usize(c::getxattr(
path.as_ptr(),
name.as_ptr(),
ptr,
value.len(),
0,
c::XATTR_NOFOLLOW,
))
}
}
}

Expand Down

0 comments on commit 10361e7

Please sign in to comment.