feature/remove-statics-from-parser-fuzzer #13

Merged
jturnerusa merged 4 commits from feature/remove-statics-from-parser-fuzzer into master 2025-12-14 19:42:50 -06:00
Showing only changes of commit b0f68fa7e0 - Show all commits

View File

@@ -3,26 +3,10 @@
use core::slice;
use gentoo_utils::{Parseable, atom::Atom};
use std::{
io::{self, Write},
sync::{LazyLock, Mutex},
};
#[derive(Debug)]
struct State {
input: io::Stdin,
output: io::Stdout,
}
use std::io::{self, Write};
#[unsafe(no_mangle)]
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 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;
}
let mut state = PIPES.lock().unwrap();
writeln!(&mut state.output, "{str}").unwrap();
let stdin = io::stdin();
let mut stdout = io::stdout();
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() {
"0" => Ok(()),