From 2ed0677286cc83deea230e8ceea0f73899acaab0 Mon Sep 17 00:00:00 2001 From: Nils Andreas Svee Date: Thu, 7 May 2026 20:34:34 +0700 Subject: [PATCH] fix(client): harden ancillary receive parsing --- crates/irtt-client/src/receive/linux.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/irtt-client/src/receive/linux.rs b/crates/irtt-client/src/receive/linux.rs index c6e52e0..f1b2361 100644 --- a/crates/irtt-client/src/receive/linux.rs +++ b/crates/irtt-client/src/receive/linux.rs @@ -66,6 +66,12 @@ pub(crate) fn recv_datagram( if len < 0 { 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 meta = unsafe { // SAFETY: `msg` was initialized by a successful `recvmsg` call. The @@ -75,7 +81,7 @@ pub(crate) fn recv_datagram( }; Ok(ReceivedDatagram { - len: len as usize, + len, received_at, meta, })