mirror of
https://github.com/CyberSecurityUP/NeuroSploit.git
synced 2026-12-05 02:24:17 +01:00
Merge pull request #133 from JoasASantos/fix/run-futures-not-send
fix(pipeline): keep the run futures Send so the binaries compile again
This commit is contained in:
2 files changed
+42
-6
No files matched your search
@@ -6178,12 +6178,19 @@ async fn finish(cfg: RunConfig, _lib: &Library, pool: &ModelPool, recon: String,
|
||||
// Persist traffic recording if enabled.
|
||||
if crate::traffic_record::enabled() {
|
||||
if let Some(ref wd) = cfg.workdir {
|
||||
let log = crate::traffic_record::store();
|
||||
let json_path = std::path::Path::new(wd).join("traffic.json");
|
||||
let _ = crate::traffic_record::save_json(&log, &json_path.to_string_lossy());
|
||||
let har_path = std::path::Path::new(wd).join("traffic.har");
|
||||
let _ = std::fs::write(&har_path, crate::traffic_record::export_har(&log));
|
||||
let summary = log.stats();
|
||||
// The guard must not survive into the await below. std::sync's
|
||||
// MutexGuard is not Send, and holding one across a suspension
|
||||
// point makes the whole run future non-Send — which tokio::spawn
|
||||
// requires, so both binaries stop compiling while the library
|
||||
// still builds clean on its own.
|
||||
let summary = {
|
||||
let log = crate::traffic_record::store();
|
||||
let json_path = std::path::Path::new(wd).join("traffic.json");
|
||||
let _ = crate::traffic_record::save_json(&log, &json_path.to_string_lossy());
|
||||
let har_path = std::path::Path::new(wd).join("traffic.har");
|
||||
let _ = std::fs::write(&har_path, crate::traffic_record::export_har(&log));
|
||||
log.stats()
|
||||
};
|
||||
let _ = tx.send(format!("📡 traffic: {} request(s), {} error(s), {} WAF block(s) → traffic.json + traffic.har",
|
||||
summary.total, summary.errors, summary.blocked)).await;
|
||||
}
|
||||
|
||||
@@ -453,3 +453,32 @@ mod tests {
|
||||
assert!(formatted.contains("2024"));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod send_tests {
|
||||
/// The run futures must stay `Send`, because both binaries hand them to
|
||||
/// `tokio::spawn`, which requires it.
|
||||
///
|
||||
/// This is easy to break from inside the library and impossible to notice
|
||||
/// there: holding a `std::sync::MutexGuard` — `traffic_record::store()`
|
||||
/// returns one — across an `.await` makes the enclosing future non-Send,
|
||||
/// and `cargo check -p neurosploit-harness` still passes because nothing
|
||||
/// in the library spawns them. Only the binaries fail, which is how the
|
||||
/// release binary came to be three weeks older than the source.
|
||||
#[test]
|
||||
fn the_run_futures_are_send() {
|
||||
fn assert_send<T: Send>(_: &T) {}
|
||||
|
||||
let cfg = crate::types::RunConfig::new("example.test");
|
||||
let lib = crate::agents::Library::default();
|
||||
let pool = crate::pool::ModelPool::new(Vec::new(), 1);
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<String>(1);
|
||||
|
||||
assert_send(&crate::pipeline::run(cfg.clone(), &lib, &pool, tx.clone()));
|
||||
assert_send(&crate::pipeline::run_whitebox(cfg.clone(), &lib, &pool, tx.clone()));
|
||||
assert_send(&crate::pipeline::run_greybox(cfg.clone(), &lib, &pool, tx.clone()));
|
||||
assert_send(&crate::pipeline::run_host(cfg.clone(), &lib, &pool, tx.clone()));
|
||||
assert_send(&crate::pipeline::run_container(cfg.clone(), &lib, &pool, tx.clone()));
|
||||
assert_send(&crate::pipeline::run_mobile(cfg, &lib, &pool, tx));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user