Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Include Debug-formatted output in fuzzer output #48

Closed
wants to merge 1 commit into from

Conversation

Manishearth
Copy link
Member

Fixes https://github.com/rust-fuzz/libfuzzer-sys/issues/47

This is really a proof of concept. Ideally we can upstream LLVMFuzzerCustomOutput, and also we can make this work so that it is able to turn itself off for types that don't implement Debug.

Thoughts? @nagisa @fitzgen

@Manishearth
Copy link
Member Author

If folks like this approach I'll go ahead and try to upstream the libfuzzer patch.

@fitzgen
Copy link
Member

fitzgen commented Nov 26, 2019

Does this only get called when a bug is found?

@Manishearth
Copy link
Member Author

Yep.

@Manishearth
Copy link
Member Author

Fuzzer::DumpCurrentUnit is what libfuzzer uses to dump out the failing test string at the end, in multiple formats (bytestring, list of hex bytes, base64, and to a file).

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wonderful, thank you Manish!

Err(_) => return,
};

println!("Formatted: {:?}", data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably make Debug a super trait of Arbitrary, I think. IIRC, it is for quickcheck's version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with that! cc @nagisa


let data: $dty = match Arbitrary::arbitrary(&mut buf) {
Ok(d) => d,
Err(_) => return,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These error cases should probably fall back to the default outputter, and print the bytes or whatever, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see that they will, since this is additional output, not replacing the existing output.

@@ -183,6 +183,9 @@ void Fuzzer::DumpCurrentUnit(const char *Prefix) {
PrintHexArray(CurrentUnitData, UnitSize, "\n");
PrintASCII(CurrentUnitData, UnitSize, "\n");
}
if (EF->LLVMFuzzerCustomOutput) {
EF->LLVMFuzzerCustomOutput(CurrentUnitData, CurrentUnitSize);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to call custom user code last, after the test case has been written to a file, just in case the custom user output code panics again or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works. I'm going to be submittign this patch upstream anyway.

@Manishearth
Copy link
Member Author

Upstreaming at https://reviews.llvm.org/D70738

@fitzgen
Copy link
Member

fitzgen commented Jan 10, 2020

We did an alternative implementation in #53

@fitzgen fitzgen closed this Jan 10, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide way to run Debug on fuzzer output
2 participants