remove static variables from atom parser fuzzer
Stdin and Stdout are already synchronized and available to multiple threads as needed, we don't need to hold onto instances in a static variable.
This commit is contained in:
@@ -3,26 +3,10 @@
|
|||||||
|
|
||||||
use core::slice;
|
use core::slice;
|
||||||
use gentoo_utils::{Parseable, atom::Atom};
|
use gentoo_utils::{Parseable, atom::Atom};
|
||||||
use std::{
|
use std::io::{self, Write};
|
||||||
io::{self, Write},
|
|
||||||
sync::{LazyLock, Mutex},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct State {
|
|
||||||
input: io::Stdin,
|
|
||||||
output: io::Stdout,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub unsafe extern "C" fn LLVMFuzzerTestOneInput(input: *const u8, len: usize) -> i32 {
|
pub unsafe extern "C" fn LLVMFuzzerTestOneInput(input: *const u8, len: usize) -> i32 {
|
||||||
static PIPES: LazyLock<Mutex<State>> = LazyLock::new(|| {
|
|
||||||
Mutex::new(State {
|
|
||||||
input: io::stdin(),
|
|
||||||
output: io::stdout(),
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
let slice = unsafe { slice::from_raw_parts(input, len) };
|
let slice = unsafe { slice::from_raw_parts(input, len) };
|
||||||
let str = str::from_utf8(slice).expect("expected ascii input");
|
let str = str::from_utf8(slice).expect("expected ascii input");
|
||||||
|
|
||||||
@@ -30,13 +14,13 @@ pub unsafe extern "C" fn LLVMFuzzerTestOneInput(input: *const u8, len: usize) ->
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut state = PIPES.lock().unwrap();
|
let stdin = io::stdin();
|
||||||
|
let mut stdout = io::stdout();
|
||||||
writeln!(&mut state.output, "{str}").unwrap();
|
|
||||||
|
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
|
|
||||||
state.input.read_line(&mut buffer).unwrap();
|
writeln!(&mut stdout, "{str}").unwrap();
|
||||||
|
|
||||||
|
stdin.read_line(&mut buffer).unwrap();
|
||||||
|
|
||||||
let control = match buffer.as_str().trim() {
|
let control = match buffer.as_str().trim() {
|
||||||
"0" => Ok(()),
|
"0" => Ok(()),
|
||||||
|
|||||||
Reference in New Issue
Block a user