From b53fb068f5216b356a5634db28681728c2d43fc2 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Sat, 21 Dec 2024 01:41:05 -0500 Subject: [PATCH] fix: MAX_DURATION overflows on init Closes: #33 `Duration` is stored as microseconds internally. The original code caused an overflow by... ```rust Duration::from_millis(u64::MAX); ``` ...which caused `u64::MAX` to be multiplied by 1000 and overflow. --- src/smolnetd/scheme/mod.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 4adcc55313..789efc07c1 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -40,8 +40,8 @@ mod udp; type SocketSet = SmoltcpSocketSet<'static>; type Interface = Rc>; -const MAX_DURATION: Duration = Duration::from_millis(u64::MAX); -const MIN_DURATION: Duration = Duration::from_millis(0); +const MAX_DURATION: Duration = Duration::from_micros(u64::MAX); +const MIN_DURATION: Duration = Duration::from_micros(0); pub struct Smolnetd { router_device: Tracer, @@ -108,11 +108,9 @@ impl Smolnetd { "127.0.0.1".parse().unwrap(), )); - - let mut eth0 = EthernetLink::new( - "eth0", - unsafe { File::from_raw_fd(network_file.into_raw() as RawFd) }, - ); + let mut eth0 = EthernetLink::new("eth0", unsafe { + File::from_raw_fd(network_file.into_raw() as RawFd) + }); eth0.set_mac_address(hardware_addr); devices.borrow_mut().push(loopback);