Closed
Description
The recvmmsg system call can result in fewer than the specified number of message buffers being filled. For example if the system call is interrupted after some data has been received. However the implementation of nix::sys::socket::recvmmsg()
does not allow for this and unconditionally attempts to process all of the message buffers, and crashes with a failed assertion.
Fortunately, I believe the fix is simple.
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index 5e5fb8d..98203bf 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -1219,7 +1219,7 @@ pub fn recvmmsg<'a, I>(
let r = Errno::result(ret)?;
Ok(output
- .into_iter()
+ .into_iter().take(ret as usize)
.zip(addresses.iter().map(|addr| unsafe{addr.assume_init()}))
.zip(results.into_iter())
.map(|((mmsghdr, address), (msg_controllen, cmsg_buffer))| {
Metadata
Metadata
Assignees
Labels
No labels