async-rs/async-log

Unsound usage of no_mangle

Nemo157 opened this issue · 1 comments

#[no_mangle]
pub fn async_log_capture_caller() {
    panic!("wat");
}

fn main() {
    std::env::set_var("RUST_BACKTRACE", "1");
    async_log::Logger::wrap(femme::pretty::Logger::new(), || 12)
        .start(log::LevelFilter::Trace)
        .unwrap();
    log::info!("Hello, world!");
    async_log_capture_caller();
}
> cargo add femme@1 async-log@2 log@0.4
> cargo run
     Running `target/debug/foo`
●  Hello, world!, filename=/private/var/folders/0p/5yvmrvhj5w3_vy1y8x7dvk7m0000gn/T/tmp.AWJu4vYd/foo/src/main.rs, line=11, fn_name=foo::main::h3c9bc8b278fd41da
   src/main.rs:11
   › thread_id: 1
   › task_id: 12

[1]    76248 segmentation fault  cargo run

You have no guarantees that there is no other crate or non-Rust linked code using the global symbol async_log_capture_caller, so this crate should document that it reserves that name for its internal usage.

@Nemo157 Oh that's a fun find; thanks for sharing! Yeah good call to add no_mangle to the unsafe_code lint.