stop panicking in case of internal error

This commit is contained in:
Tamo 2021-11-04 16:20:53 +01:00
parent 3e5550c910
commit 7328ffb034
No known key found for this signature in database
GPG key ID: 20CD8020AFA88D69
4 changed files with 26 additions and 14 deletions

View file

@ -1,13 +1,18 @@
#![no_main]
use filter_parser::FilterCondition;
use filter_parser::{ErrorKind, FilterCondition};
use libfuzzer_sys::fuzz_target;
fuzz_target!(|data: &[u8]| {
if let Ok(s) = std::str::from_utf8(data) {
// When we are fuzzing the parser we can get stack overflow really easily.
// When we are fuzzing the parser we can get a stack overflow very easily.
// But since this doesn't happens with a normal build we are just going to limit the fuzzer to 500 characters.
if s.len() < 500 {
let _ = FilterCondition::parse(s);
match FilterCondition::parse(s) {
Err(e) if matches!(e.kind(), ErrorKind::InternalError(_)) => {
panic!("Found an internal error: `{:?}`", e)
}
_ => (),
}
}
}
});