Files
gentoo-utils-gitea/fuzz/atom/parser/fuzz.rs
John Turner 87e9d1920c
All checks were successful
Gentoo Utils / build-oci-image (push) Successful in 19s
Gentoo Utils / check-format (push) Successful in 10s
Gentoo Utils / docs (push) Successful in 13s
Gentoo Utils / build (push) Successful in 24s
Gentoo Utils / test (push) Successful in 29s
allow fuzzer disagreements where there are duplicated usedeps in the atom
Portage rejects atoms with duplicated usedeps that are otherwise
valid, gentoo-utils accepts these as valid however. So we will not
panic on cases of disagreement where the control side fails and we
detect duplicated usedeps.
2025-12-14 02:53:49 +00:00

76 lines
1.9 KiB
Rust

#![deny(unused_imports)]
#![allow(clippy::missing_safety_doc)]
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,
}
#[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");
if str.chars().any(|c| !c.is_ascii_graphic()) {
return -1;
}
let mut state = PIPES.lock().unwrap();
writeln!(&mut state.output, "{str}").unwrap();
let mut buffer = String::new();
state.input.read_line(&mut buffer).unwrap();
let control = match buffer.as_str().trim() {
"0" => Ok(()),
"1" => Err(()),
other => panic!("unexpected input from pipes: {other}"),
};
let gentoo_utils = Atom::parse(str);
match (control, gentoo_utils) {
(Ok(_), Ok(_)) => {
eprintln!("agreement that {str} is valid");
}
(Err(_), Err(_)) => {
eprintln!("agreement that {str} is invalid");
}
(Ok(_), Err(rest)) => {
panic!("disagreement on {str}\ncontrol:Ok\ngentoo-utils:Err({rest})");
}
(Err(_), Ok(atom))
if atom
.usedeps()
.iter()
.any(|usedep| atom.usedeps().iter().filter(|u| usedep == *u).count() > 1) =>
{
eprintln!(
"disagreement, but we will allow it since its probably because of duplicated usdeps"
);
}
(Err(_), Ok(_)) => {
panic!("disagreement on {str}\ncontrol:Err\ngentoo-utils:Ok")
}
}
0
}