dtolnay / inventory

Typed distributed plugin registration
Apache License 2.0
948 stars 43 forks source link

Unsound usages of unsafe implementation from immut to mut #73

Closed llooFlashooll closed 1 month ago

llooFlashooll commented 1 month ago

Hi, I am scanning the inventory in the latest version with my own static analyzer tool.

Unsafe conversion found at: src/lib.rs:196:27: 196:58

let new_ptr = new as *const Node as *mut Node;

unsafe fn submit(&'static self, new: &'static Node) {
    let mut head = self.head.load(Ordering::Relaxed);
    loop {
        unsafe {
            *new.next.get() = head.as_ref();
        }
        let new_ptr = new as *const Node as *mut Node;
        match self
            .head
            .compare_exchange(head, new_ptr, Ordering::Release, Ordering::Relaxed)
        {
            Ok(_) => return,
            Err(prev) => head = prev,
        }
    }
}

This would potentially cause undefined behaviors in Rust. I am reporting this issue for your attention. Probably can further wrap it into unsafe code block. This is just a tiny issue to conclude.

dtolnay commented 1 month ago

This is the second low-effort, incorrect report you have filed on my repos, and I have seen at least 3 more similarly poor issues you have opened recently in other repos I follow.

Please do not open another issue on any repo owned by me or you will be banned.

llooFlashooll commented 1 month ago

Hi, I feel sorry. Since my tool has some FP, after I collected it, I didn't make a further PoC to prove it. I didn't intend to do this. Sorry again. I am a student who is currently doing research and is not familiar. Sorry for any inconvenience I have caused. I will be much more careful.