Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsound usage of no_mangle #13

Open
Nemo157 opened this issue Aug 1, 2020 · 1 comment
Open

Unsound usage of no_mangle #13

Nemo157 opened this issue Aug 1, 2020 · 1 comment

Comments

@Nemo157
Copy link

Nemo157 commented Aug 1, 2020

#[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 [email protected]
> 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.

@yoshuawuyts
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants