From 73cc2f5b9c338e95f33aeb049ff3e810a704df25 Mon Sep 17 00:00:00 2001 From: lazymio Date: Mon, 19 May 2025 05:17:29 +0800 Subject: [PATCH] Make unique_std_input_file more unique (#3247) --- libafl_bolts/src/fs.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libafl_bolts/src/fs.rs b/libafl_bolts/src/fs.rs index fd4fdae8f3..b4c5b89819 100644 --- a/libafl_bolts/src/fs.rs +++ b/libafl_bolts/src/fs.rs @@ -1,7 +1,10 @@ //! `LibAFL` functionality for filesystem interaction +use core::sync::atomic::AtomicU64; +use core::sync::atomic::Ordering; #[cfg(unix)] use std::os::unix::prelude::{AsRawFd, RawFd}; +use std::sync::OnceLock; use alloc::string::String; use alloc::sync::Arc; @@ -23,7 +26,11 @@ pub const INPUTFILE_STD: &str = ".cur_input"; /// Derives a filename from [`INPUTFILE_STD`] that may be used to deliver testcases to the target. /// It ensures the filename is unique to the fuzzer process. pub fn get_unique_std_input_file() -> String { - format!("{}_{}", INPUTFILE_STD, std::process::id()) + static STD_COUNT: OnceLock = OnceLock::new(); + let next = STD_COUNT + .get_or_init(|| AtomicU64::new(0)) + .fetch_add(1, Ordering::SeqCst); + format!("{}_{}_{}", INPUTFILE_STD, std::process::id(), next) } /// Write a file atomically