Skip to content

Commit b138431

Browse files
committed
fix(netwatch): guard divide-by-zero in poll_recv_noq trace
`UdpSocket::poll_recv_noq` evaluated `meta.len / meta.stride` directly inside `trace!()` macro arguments. `noq_udp::RecvMeta.stride` is allowed to be `0` in practice on the GRO path (empty datagrams, kernel falling back to a non-segmented receive), which crashes the host process with `attempt to divide by zero` — observed on Windows 11 24H2 and macOS 15.4/26.x against netwatch 0.16.0/0.17.0. Replace the bare division with `checked_div(...).unwrap_or(0)` so the trace field reports `0` when `stride == 0` and stays identical otherwise. Closes #148.
1 parent 7c952d5 commit b138431

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

netwatch/src/udp.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,12 @@ impl UdpSocket {
433433
trace!(
434434
src = %meta.addr,
435435
len = meta.len,
436-
count = meta.len / meta.stride,
436+
// `stride == 0` is reachable in practice on the GRO path
437+
// (e.g. empty datagrams, kernel falling back to a
438+
// non-segmented receive), so guard the division to
439+
// avoid a divide-by-zero panic inside the trace
440+
// macro arguments. See n0-computer/net-tools#148.
441+
count = meta.len.checked_div(meta.stride).unwrap_or(0),
437442
dst = %meta.dst_ip.map(|x| x.to_string()).unwrap_or_default(),
438443
"UDP recv"
439444
);

0 commit comments

Comments
 (0)