[domistream] Tests: fuzz targets assert invariants
Every target now checks properties instead of only calling the parser: parse -> encode -> parse stability (RTSP request, ENet, input), caps and TooLarge past them, chunking invariance of the framer, XML vs status parser agreement, seal/open round trips, no forged GCM tags. New targets for the parsers and state machines that had none: server_cert_der, enet_client, media_decrypt, video_depacketizer, audio_depacketizer, fec_reconstruct, pairing_session, rtsp_client (25 targets).
This commit is contained in:
@@ -1,11 +1,24 @@
|
||||
//! Fuzzes the host certificate PEM (`plaincert`): never panics, whatever the bytes.
|
||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
||||
//! Fuzzes the host certificate PEM (`plaincert`).
|
||||
//! Asserts invariants, not only "no panic": an accepted PEM gives a DER that loads again, equals itself, pins itself, and has a signature.
|
||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
||||
|
||||
#![no_main]
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
use domistream::pairing::ServerCert;
|
||||
use domistream::pairing::identity::{MAX_CERT_DER_BYTES, MAX_CERT_PEM_BYTES};
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let _ = domistream::pairing::ServerCert::from_pem(data);
|
||||
let r = ServerCert::from_pem(data);
|
||||
if data.len() > MAX_CERT_PEM_BYTES {
|
||||
assert!(matches!(r, Err(domistream::Error::TooLarge { .. })));
|
||||
}
|
||||
if let Ok(c) = r {
|
||||
assert!(c.der().len() <= MAX_CERT_DER_BYTES);
|
||||
let again = ServerCert::from_der(c.der()).expect("the DER of an accepted PEM loads");
|
||||
assert_eq!(again, c);
|
||||
assert_eq!(c.matches(c.der()), Ok(true));
|
||||
assert!(!c.signature().expect("signature").is_empty());
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user