nulldotblack / wintun

Rust bindings to the wintun c library: https://www.wintun.net/
MIT License
71 stars 19 forks source link

Crash in Adapter::create #2

Closed lazytiger closed 2 years ago

lazytiger commented 2 years ago

I wrote some test code like the following

let wintun = unsafe { wintun::load_from_path(&OPTIONS.wintun_args().wintun).unwrap() };
    println!("library loaded");
    let pool = "test";
    let name = "trojan";
    let adapter = match Adapter::open(&wintun, pool, name) {
        Ok(adapter) => adapter,
        Err(_) => Adapter::create(&wintun, pool, name, None).unwrap().adapter,
    };
    println!("adapter created");
    let session = Arc::new(adapter.start_session(wintun::MAX_RING_CAPACITY).unwrap());
    println!("session created");
    while let Ok(p) = session.receive_blocking() {
        println!("{}", p.bytes().len());
    }

crash information: exit code: 0xc0000005, STATUS_ACCESS_VIOLATION But it crashed in Adapter::open. With a debugger, I can see more details, and it seems default_logger function crashed, because message parameter is invalid

lazytiger commented 2 years ago

My bad, I used a 0.14.1 version, but wintun-rust used a 0.13 version

TroyNeubauer commented 2 years ago

Thanks for bringing this to my attention. I'll start on 0.14 support right away. Looks like wintun refactored WintunDeleteAdapter to be WintunCloseAdapter like what happened for Wireguard recently: https://github.com/nulldotblack/wireguard-nt/issues/3

lazytiger commented 2 years ago

Just a suggestion, maybe some version check and a more specific error could be a better solution. I just debugged and followed the Wintun header files to find that was a version problem.

TroyNeubauer commented 2 years ago

Absolutely, I have added the dynamic-link-require-all flag to bindgen on the 0-14_support branch, which will cause calls to load and friends to return Err() immediately when attempting to load older (< version 0.14) drivers. After a bit more testing this should be out soon, hopefully with your PR as well :)

lazytiger commented 2 years ago

That's very kind, thanks.