lockbud icon indicating copy to clipboard operation
lockbud copied to clipboard

Duplicated warnings in ConflictLock Detector

Open soyo114 opened this issue 1 month ago • 0 comments

Description

Hi, when using LockBud to detect ConflictLock vulnerabilities, I found that it generates some duplicate warnings. Please see the code example and the analysis results below. I used the command cargo lockbud -k all to invoke LockBud.

Code Example

use std::sync::{Arc, Mutex};
use std::thread;
macro_rules! lock_and_execute {
    ($a:expr, $b:expr, $body:block) => {
        let _a = $a.lock().unwrap();
        let _b = $b.lock().unwrap();
        $body
    };
}
fn func() {
    let lock_a1 = Arc::new(Mutex::new(1));
    let lock_b1 = Arc::new(Mutex::new(true));
    let lock_a2 = lock_a1.clone();
    let lock_b2 = lock_b1.clone();
    lock_and_execute!(lock_b1, lock_a1, {});
    let th = thread::spawn(move || {
        lock_and_execute!(lock_a2, lock_b2, {});
    });
    th.join().unwrap();
}
fn main() {
    func();
}

Expected Behavior

Lockbud should issue only one ConflictLockwarning for the locks at lines 15 and 17, but it reported multiple identical warnings.

Part of Analysis Results

ConflictLock warning 1

"first_lock_type": "StdMutex(i32)",
"first_lock_span": "src/main.rs:6:13: 6:15 (#8)",
"second_lock_type": "StdMutex(bool)",
"second_lock_span": "src/main.rs:6:13: 6:15 (#30)",

"first_lock_type": "StdMutex(bool)",
"first_lock_span": "src/main.rs:5:13: 5:15 (#8)",
"second_lock_type": "StdMutex(i32)",
"second_lock_span": "src/main.rs:5:13: 5:15 (#30)",

ConflictLock warning 2

"first_lock_type": "StdMutex(i32)",
"first_lock_span": "src/main.rs:6:13: 6:15 (#8)",
"second_lock_type": "StdMutex(bool)",
"second_lock_span": "src/main.rs:6:13: 6:15 (#30)",

"first_lock_type": "StdMutex(bool)",
"first_lock_span": "src/main.rs:5:13: 5:15 (#8)",
"second_lock_type": "StdMutex(i32)",
"second_lock_span": "src/main.rs:6:13: 6:15 (#8)",

ConflictLock warning 3

"first_lock_type": "StdMutex(i32)",
"first_lock_span": "src/main.rs:5:13: 5:15 (#30)",
"second_lock_type": "StdMutex(bool)",
"second_lock_span": "src/main.rs:6:13: 6:15 (#30)",

"first_lock_type": "StdMutex(bool)",
"first_lock_span": "src/main.rs:5:13: 5:15 (#8)",
"second_lock_type": "StdMutex(i32)",
"second_lock_span": "src/main.rs:6:13: 6:15 (#8)",

soyo114 avatar Nov 03 '25 13:11 soyo114