fix(client): harden ancillary receive parsing

This commit is contained in:
Nils Andreas Svee committed 2026-05-07 20:34:34 +07:00
1 parent 49321ba8b7
commit 2ed0677286
1 file changed
+7 -1
+7 -1
View File
@@ -66,6 +66,12 @@ pub(crate) fn recv_datagram(
if len < 0 { if len < 0 {
return Err(io::Error::last_os_error()); return Err(io::Error::last_os_error());
} }
let len = usize::try_from(len).map_err(|_| {
io::Error::new(
io::ErrorKind::InvalidData,
"recvmsg returned an unrepresentable datagram length",
)
})?;
let received_at = ClientTimestamp::now(); let received_at = ClientTimestamp::now();
let meta = unsafe { let meta = unsafe {
// SAFETY: `msg` was initialized by a successful `recvmsg` call. The // SAFETY: `msg` was initialized by a successful `recvmsg` call. The
@@ -75,7 +81,7 @@ pub(crate) fn recv_datagram(
}; };
Ok(ReceivedDatagram { Ok(ReceivedDatagram {
len: len as usize, len,
received_at, received_at,
meta, meta,
}) })