-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci(x509): smoke test x509 via fuzzing #446
Conversation
As expected, fuzzing has caused
|
Can you rebase now that #445 is merged? |
I managed to reproduce the panic and get the stack trace:
It's failing on parsing The implementation is not validating that there is sufficient space in the output buffer when attempting to add leading zeroes. So this is ultimately a bug in the Edit: prospective fix in #447 |
The previous implementation used `saturating_sub` rather than `checked_sub` to compute the number of leading zeroes to use, which would cause a panic if the input exceeded the output (see #446). This commit switches to `checked_sub`, returning `ErrorKind::Length` in the event the output buffer is too small for the given input. It also adds unit tests for this behavior as well as the happy paths.
The previous implementation used `saturating_sub` rather than `checked_sub` to compute the number of leading zeroes to use, which would cause a panic if the input exceeded the output (see #446). This commit switches to `checked_sub`, returning `ErrorKind::Length` in the event the output buffer is too small for the given input. It also adds unit tests for this behavior as well as the happy paths.
This adds fuzzing targets to the x509 crate that make use of libfuzzer (via cargo-fuzz) to fuzz types whose parsers are expected to be exposed to untrusted inputs: x509::request::{CertReq, CertReqInfo}. On their own, the fuzzing targets can be run manually via `cargo fuzz run <name of binary>`. Anyone hunting for parser bugs in this crate needs only to fire up the fuzzer and let it run for as long as they like. This commit also adds a CI action that runs each fuzzer for 30 seconds. This action serves as a smoke test to provide a basic degree of confidence in the quality of any PR that touches this crate.
@tarcieri I actually had a patch fixing the bug on my end, but I was letting the fuzzer run on it for a few hours to see if it would find anything else and you beat me to the punch. :) In any case, this looks fairly solid now. How do you feel about having this run in CI? I'm happy to increase or reduce the time as you see fit; they're your CI minutes, after all. :P |
@bstrie might be interesting to e.g. run on a schedule so it doesn’t block the normal CI flow, but in general it seems like a good idea |
@bstrie I think fuzzing both |
Will go ahead and land this. If it turns out to take up too much CI time, we can convert it to a scheduled job. |
This adds fuzzing targets to the x509 crate that make use of libfuzzer (via cargo-fuzz) to fuzz types whose parsers are expected to be exposed to untrusted inputs:
x509::request::{CertReq, CertReqInfo}
.On their own, the fuzzing targets can be run manually via
cargo fuzz run <name of binary>
. Anyone hunting for parser bugs in this crate needs only to fire up the fuzzer and let it run for as long as they like.This commit also adds a CI action that runs each fuzzer for 30 seconds. This action serves as a smoke test to provide a basic degree of confidence in the quality of any PR that touches this crate.
Note: this PR is absolutely going to fail CI for now. It turns out that the parsers in question have a number of panics that are quite trivial to surface. The fact that it's so easy to crash these parsers should hopefully demonstrate the value of these smoke tests. However, obviously this should not be merged until these panics are fixed. :P