diff --git a/netstack/src/scheme/mod.rs b/netstack/src/scheme/mod.rs index 18e2cc2a8e..8b0a6a141a 100644 --- a/netstack/src/scheme/mod.rs +++ b/netstack/src/scheme/mod.rs @@ -178,9 +178,11 @@ impl Smolnetd { } else { name }; - let mut link = EthernetLink::new(&dev_name, // SAFETY: caller must verify the safety contract for this operation -unsafe { - File::from_raw_fd(nf.into_raw() as RawFd) + let mut link = EthernetLink::new(&dev_name, // SAFETY: caller guarantees nf is a live Fd not aliased + // elsewhere; from_raw_fd transfers ownership + // to the new File. + unsafe { + File::from_raw_fd(nf.into_raw()) }); link.set_mac_address(hw_addr); devices.borrow_mut().push(link); @@ -191,8 +193,10 @@ unsafe { router_device: network_device, socket_set: Rc::clone(&socket_set), timer: ::std::time::Instant::now(), - time_file: // SAFETY: caller guarantees fd is valid, open, and not aliased -unsafe { File::from_raw_fd(time_file.into_raw() as RawFd) }, + time_file: // SAFETY: caller guarantees time_file is a live Fd not + // aliased elsewhere; from_raw_fd transfers ownership + // to the new File. + unsafe { File::from_raw_fd(time_file.into_raw()) }, ip_scheme: IpScheme::new( "ip", Rc::clone(&iface),