afl: add debug feature
leave out debug prints when actually fuzzing to increase fuzz performance
This commit is contained in:
parent
9a7c57f524
commit
0d884a65d5
3 changed files with 28 additions and 4 deletions
4
Makefile
4
Makefile
|
@ -60,7 +60,7 @@ AFL_TARGET_CRASH?=crashes
|
||||||
afl:
|
afl:
|
||||||
rm -rf tests/afl/out
|
rm -rf tests/afl/out
|
||||||
(cd tests/afl && \
|
(cd tests/afl && \
|
||||||
cargo afl build --release --config profile.release.debug-assertions=true && \
|
cargo afl build --no-default-features --release --config profile.release.debug-assertions=true && \
|
||||||
(AFL_NO_UI=1 cargo afl fuzz -i in -o out -Mm target/release/${AFL_TARGET} &) && \
|
(AFL_NO_UI=1 cargo afl fuzz -i in -o out -Mm target/release/${AFL_TARGET} &) && \
|
||||||
for i in $$(seq $$((${AFL_JOBS} - 1))); do \
|
for i in $$(seq $$((${AFL_JOBS} - 1))); do \
|
||||||
AFL_NO_UI=1 cargo afl fuzz -i in -o out -Ss$$i target/release/${AFL_TARGET} & \
|
AFL_NO_UI=1 cargo afl fuzz -i in -o out -Ss$$i target/release/${AFL_TARGET} & \
|
||||||
|
@ -71,7 +71,7 @@ afl:
|
||||||
afl_quick:
|
afl_quick:
|
||||||
rm -rf tests/afl/out
|
rm -rf tests/afl/out
|
||||||
(cd tests/afl && \
|
(cd tests/afl && \
|
||||||
cargo afl build --release --config profile.release.debug-assertions=true && \
|
cargo afl build --no-default-features --release --config profile.release.debug-assertions=true && \
|
||||||
AFL_NO_UI=1 AFL_BENCH_UNTIL_CRASH=1 \
|
AFL_NO_UI=1 AFL_BENCH_UNTIL_CRASH=1 \
|
||||||
cargo afl fuzz -i in -o out -V 60 target/release/${AFL_TARGET})
|
cargo afl fuzz -i in -o out -V 60 target/release/${AFL_TARGET})
|
||||||
|
|
||||||
|
|
|
@ -20,3 +20,7 @@ path = "src/parse.rs"
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "html"
|
name = "html"
|
||||||
path = "src/html.rs"
|
path = "src/html.rs"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["debug"]
|
||||||
|
debug = []
|
||||||
|
|
|
@ -26,13 +26,18 @@ pub fn html(data: &[u8]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_html(html: &str) {
|
fn validate_html(html: &str) {
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
let mut has_error = false;
|
let mut has_error = false;
|
||||||
|
|
||||||
html5ever::parse_document(
|
html5ever::parse_document(
|
||||||
Dom {
|
Dom {
|
||||||
names: Vec::new(),
|
names: Vec::new(),
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
has_error: &mut has_error,
|
has_error: &mut has_error,
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
line_no: 1,
|
line_no: 1,
|
||||||
|
#[cfg(not(feature = "debug"))]
|
||||||
|
_lifetime: std::marker::PhantomData,
|
||||||
},
|
},
|
||||||
html5ever::ParseOpts {
|
html5ever::ParseOpts {
|
||||||
tokenizer: tokenizer::TokenizerOpts {
|
tokenizer: tokenizer::TokenizerOpts {
|
||||||
|
@ -50,6 +55,7 @@ fn validate_html(html: &str) {
|
||||||
.read_from(&mut std::io::Cursor::new(html))
|
.read_from(&mut std::io::Cursor::new(html))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
if has_error {
|
if has_error {
|
||||||
eprintln!("html:");
|
eprintln!("html:");
|
||||||
html.split('\n').enumerate().for_each(|(i, l)| {
|
html.split('\n').enumerate().for_each(|(i, l)| {
|
||||||
|
@ -62,8 +68,12 @@ fn validate_html(html: &str) {
|
||||||
|
|
||||||
struct Dom<'a> {
|
struct Dom<'a> {
|
||||||
names: Vec<html5ever::QualName>,
|
names: Vec<html5ever::QualName>,
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
has_error: &'a mut bool,
|
has_error: &'a mut bool,
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
line_no: u64,
|
line_no: u64,
|
||||||
|
#[cfg(not(feature = "debug"))]
|
||||||
|
_lifetime: std::marker::PhantomData<&'a ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> tree_builder::TreeSink for Dom<'a> {
|
impl<'a> tree_builder::TreeSink for Dom<'a> {
|
||||||
|
@ -110,16 +120,26 @@ impl<'a> tree_builder::TreeSink for Dom<'a> {
|
||||||
"Unexpected open element while closing",
|
"Unexpected open element while closing",
|
||||||
];
|
];
|
||||||
if !whitelist.iter().any(|e| msg.starts_with(e)) {
|
if !whitelist.iter().any(|e| msg.starts_with(e)) {
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
|
{
|
||||||
*self.has_error = true;
|
*self.has_error = true;
|
||||||
eprintln!("{}: {}\n", self.line_no, msg);
|
eprintln!("{}: {}\n", self.line_no, msg);
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "debug"))]
|
||||||
|
{
|
||||||
|
panic!("invalid html");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_quirks_mode(&mut self, _: tree_builder::QuirksMode) {}
|
fn set_quirks_mode(&mut self, _: tree_builder::QuirksMode) {}
|
||||||
|
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
fn set_current_line(&mut self, l: u64) {
|
fn set_current_line(&mut self, l: u64) {
|
||||||
self.line_no = l;
|
self.line_no = l;
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "debug"))]
|
||||||
|
fn set_current_line(&mut self, _: u64) {}
|
||||||
|
|
||||||
fn append(&mut self, _: &usize, _: tree_builder::NodeOrText<usize>) {}
|
fn append(&mut self, _: &usize, _: tree_builder::NodeOrText<usize>) {}
|
||||||
fn append_before_sibling(&mut self, _: &usize, _: tree_builder::NodeOrText<usize>) {}
|
fn append_before_sibling(&mut self, _: &usize, _: tree_builder::NodeOrText<usize>) {}
|
||||||
|
|
Loading…
Reference in a new issue