shellrow / netdev

Cross-platform library for network interface and gateway. Written in Rust.
MIT License
65 stars 12 forks source link

MacOs panic #54

Closed marcbrevoort-cyberhive closed 8 months ago

marcbrevoort-cyberhive commented 8 months ago

We have observed an assertion failure in the version assertion in gateway/macos.rs as follows:

thread '<unnamed>' panicked at /Users/andyduplain/.cargo/registry/src/index.crates.io-6f17d22bba15001f/default-net-0.17.0/src/gateway/macos.rs:293:9:
assertion `left == right` failed
  left: 0
 right: 5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:279:5
   4: default_net::gateway::macos::list_routes
             at /Users/andyduplain/.cargo/registry/src/index.crates.io-6f17d22bba15001f/default-net-0.17.0/src/gateway/macos.rs:293:9
   5: default_net::gateway::macos::get_default_route
             at /Users/andyduplain/.cargo/registry/src/index.crates.io-6f17d22bba15001f/default-net-0.17.0/src/gateway/macos.rs:412:11
   6: default_net::gateway::macos::get_default_gateway
             at /Users/andyduplain/.cargo/registry/src/index.crates.io-6f17d22bba15001f/default-net-0.17.0/src/gateway/macos.rs:431:26
   7: default_net::interface::unix::interfaces
             at /Users/andyduplain/.cargo/registry/src/index.crates.io-6f17d22bba15001f/default-net-0.17.0/src/interface/unix.rs:63:27
   8: default_net::interface::get_default_interface
             at /Users/andyduplain/.cargo/registry/src/index.crates.io-6f17d22bba15001f/default-net-0.17.0/src/interface/mod.rs:134:38

There is only one assert in the macos.rs code,

        assert_eq!(rt_hdr.rtm_version as u32, RTM_VERSION);

which is called after the error check:

        let rt_hdr = unsafe { std::mem::transmute::<_, &rt_msghdr>(buf.as_ptr()) };
        assert_eq!(rt_hdr.rtm_version as u32, RTM_VERSION);
        if rt_hdr.rtm_errno != 0 {
            return Err(code_to_error(rt_hdr.rtm_errno));
        }

Perhaps the error check should go before the assertion?

Before jumping in, note we're currently using 0.17.0. As a version 0.21.0 is available at the time of this writing, we'll try with the most recent version of the crate and report back.

marcbrevoort-cyberhive commented 8 months ago

Update: it might be that this is fixed by

https://github.com/shellrow/default-net/commit/d26e69a77576d96e1e9210218b9123190217ad22

marcbrevoort-cyberhive commented 8 months ago

Seems to be a duplicate of #42, closing.