Merge pull request 'feature/remove-statics-from-parser-fuzzer' (#13) from feature/remove-statics-from-parser-fuzzer into master
All checks were successful
Gentoo Utils / check-format (push) Successful in 8s
Gentoo Utils / build (push) Successful in 20s
Gentoo Utils / test (push) Successful in 26s
Gentoo Utils / grep (push) Successful in 3s
Gentoo Utils / docs (push) Successful in 12s
Gentoo Utils / build-oci-image (push) Successful in 7s

Reviewed-on: #13
Reviewed-by: penguin <penguin@epenguin.net>
This commit was merged in pull request #13.
This commit is contained in:
2025-12-14 19:42:50 -06:00
2 changed files with 26 additions and 29 deletions

View File

@@ -4,25 +4,12 @@
use core::slice;
use gentoo_utils::{Parseable, atom::Atom};
use std::{
env::{self},
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");
@@ -30,13 +17,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(()),
@@ -48,23 +35,32 @@ pub unsafe extern "C" fn LLVMFuzzerTestOneInput(input: *const u8, len: usize) ->
match (control, gentoo_utils) {
(Ok(_), Ok(_)) => {
eprintln!("agreement that {str} is valid");
if env::var("FUZZER_LOG").is_ok() {
eprintln!("agreement that {str} is valid");
}
}
(Err(_), Err(_)) => {
eprintln!("agreement that {str} is invalid");
if env::var("FUZZER_LOG").is_ok() {
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) =>
if atom.usedeps().iter().any(|usedep| {
atom.usedeps()
.iter()
.filter(|u| *usedep.flag() == *u.flag())
.count()
> 1
}) =>
{
eprintln!(
"disagreement, but we will allow it since its probably because of duplicated usdeps"
);
if env::var("FUZZER_LOG").is_ok() {
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")

View File

@@ -2,12 +2,13 @@
import sys
from portage.dep import Atom
from portage.exception import InvalidAtom
for line in sys.stdin.buffer:
try:
Atom(line.decode().strip())
sys.stdout.buffer.write(b"0\n")
except:
except InvalidAtom:
sys.stdout.buffer.write(b"1\n")
finally:
sys.stdout.buffer.flush()