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
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:
@@ -4,25 +4,12 @@
|
|||||||
use core::slice;
|
use core::slice;
|
||||||
use gentoo_utils::{Parseable, atom::Atom};
|
use gentoo_utils::{Parseable, atom::Atom};
|
||||||
use std::{
|
use std::{
|
||||||
|
env::{self},
|
||||||
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 +17,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(()),
|
||||||
@@ -48,23 +35,32 @@ pub unsafe extern "C" fn LLVMFuzzerTestOneInput(input: *const u8, len: usize) ->
|
|||||||
|
|
||||||
match (control, gentoo_utils) {
|
match (control, gentoo_utils) {
|
||||||
(Ok(_), Ok(_)) => {
|
(Ok(_), Ok(_)) => {
|
||||||
eprintln!("agreement that {str} is valid");
|
if env::var("FUZZER_LOG").is_ok() {
|
||||||
|
eprintln!("agreement that {str} is valid");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(Err(_), Err(_)) => {
|
(Err(_), Err(_)) => {
|
||||||
eprintln!("agreement that {str} is invalid");
|
if env::var("FUZZER_LOG").is_ok() {
|
||||||
|
eprintln!("agreement that {str} is invalid");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(Ok(_), Err(rest)) => {
|
(Ok(_), Err(rest)) => {
|
||||||
panic!("disagreement on {str}\ncontrol:Ok\ngentoo-utils:Err({rest})");
|
panic!("disagreement on {str}\ncontrol:Ok\ngentoo-utils:Err({rest})");
|
||||||
}
|
}
|
||||||
(Err(_), Ok(atom))
|
(Err(_), Ok(atom))
|
||||||
if atom
|
if atom.usedeps().iter().any(|usedep| {
|
||||||
.usedeps()
|
atom.usedeps()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|usedep| atom.usedeps().iter().filter(|u| usedep == *u).count() > 1) =>
|
.filter(|u| *usedep.flag() == *u.flag())
|
||||||
|
.count()
|
||||||
|
> 1
|
||||||
|
}) =>
|
||||||
{
|
{
|
||||||
eprintln!(
|
if env::var("FUZZER_LOG").is_ok() {
|
||||||
"disagreement, but we will allow it since its probably because of duplicated usdeps"
|
eprintln!(
|
||||||
);
|
"disagreement, but we will allow it since its probably because of duplicated usdeps"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(Err(_), Ok(_)) => {
|
(Err(_), Ok(_)) => {
|
||||||
panic!("disagreement on {str}\ncontrol:Err\ngentoo-utils:Ok")
|
panic!("disagreement on {str}\ncontrol:Err\ngentoo-utils:Ok")
|
||||||
|
|||||||
@@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
from portage.dep import Atom
|
from portage.dep import Atom
|
||||||
|
from portage.exception import InvalidAtom
|
||||||
|
|
||||||
for line in sys.stdin.buffer:
|
for line in sys.stdin.buffer:
|
||||||
try:
|
try:
|
||||||
Atom(line.decode().strip())
|
Atom(line.decode().strip())
|
||||||
sys.stdout.buffer.write(b"0\n")
|
sys.stdout.buffer.write(b"0\n")
|
||||||
except:
|
except InvalidAtom:
|
||||||
sys.stdout.buffer.write(b"1\n")
|
sys.stdout.buffer.write(b"1\n")
|
||||||
finally:
|
finally:
|
||||||
sys.stdout.buffer.flush()
|
sys.stdout.buffer.flush()
|
||||||
|
|||||||
Reference in New Issue
Block a user