fix(client): harden ancillary receive parsing
This commit is contained in:
1 parent
56d3a905ed
commit
1a98858b7a
1 file changed
+7
-1
@@ -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,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user