Skip to content

Commit 05681c8

Browse files
authored
recvmsg requires the pointer to be either valid or NULL on Solarish. (#739)
When passing the address of a `&[]` slice to `recvmsg`, substitute in NULL so that it doesn't fail with `EFAULT`, on Solarish platforms.
1 parent c564105 commit 05681c8

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/net/send_recv/msg.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,15 @@ impl<'buf, 'slice, 'fd> SendAncillaryBuffer<'buf, 'slice, 'fd> {
107107

108108
/// Returns a pointer to the message data.
109109
pub(crate) fn as_control_ptr(&mut self) -> *mut u8 {
110-
if self.length > 0 {
111-
self.buffer.as_mut_ptr()
112-
} else {
113-
ptr::null_mut()
110+
// When the length is zero, we may be using a `&[]` address, which
111+
// may be an invalid but non-null pointer, and on some platforms, that
112+
// causes `sendmsg` to fail with `EFAULT` or `EINVAL`
113+
#[cfg(not(linux_kernel))]
114+
if self.length == 0 {
115+
return core::ptr::null_mut();
114116
}
117+
118+
self.buffer.as_mut_ptr()
115119
}
116120

117121
/// Returns the length of the message data.
@@ -223,6 +227,14 @@ impl<'buf> RecvAncillaryBuffer<'buf> {
223227

224228
/// Returns a pointer to the message data.
225229
pub(crate) fn as_control_ptr(&mut self) -> *mut u8 {
230+
// When the length is zero, we may be using a `&[]` address, which
231+
// may be an invalid but non-null pointer, and on some platforms, that
232+
// causes `sendmsg` to fail with `EFAULT` or `EINVAL`
233+
#[cfg(not(linux_kernel))]
234+
if self.buffer.is_empty() {
235+
return core::ptr::null_mut();
236+
}
237+
226238
self.buffer.as_mut_ptr()
227239
}
228240

0 commit comments

Comments
 (0)