From 4de52364db6a92de6ed45d86bc5bc59c599b7d24 Mon Sep 17 00:00:00 2001 From: Joe Birr-Pixton Date: Wed, 18 Sep 2024 12:11:40 +0100 Subject: [PATCH] Add fuzz target for PEM decoding --- fuzz/Cargo.lock | 2 +- fuzz/Cargo.toml | 7 +++++++ fuzz/corpus/pem/zen.pem | 1 + fuzz/fuzz_targets/pem.rs | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 120000 fuzz/corpus/pem/zen.pem create mode 100644 fuzz/fuzz_targets/pem.rs diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 15d45c4..2730088 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -52,7 +52,7 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "rustls-pki-types" -version = "1.3.1" +version = "1.8.0" [[package]] name = "rustls-pki-types-fuzz" diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 40ac233..4bfa301 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -12,6 +12,7 @@ libfuzzer-sys = "0.4" [dependencies.rustls-pki-types] path = ".." +features = ["std"] # Prevent this from interfering with workspaces [workspace] @@ -25,3 +26,9 @@ name = "private_key" path = "fuzz_targets/private_key.rs" test = false doc = false + +[[bin]] +name = "pem" +path = "fuzz_targets/pem.rs" +test = false +doc = false diff --git a/fuzz/corpus/pem/zen.pem b/fuzz/corpus/pem/zen.pem new file mode 120000 index 0000000..644365f --- /dev/null +++ b/fuzz/corpus/pem/zen.pem @@ -0,0 +1 @@ +../../../tests/data/zen.pem \ No newline at end of file diff --git a/fuzz/fuzz_targets/pem.rs b/fuzz/fuzz_targets/pem.rs new file mode 100644 index 0000000..8a629f5 --- /dev/null +++ b/fuzz/fuzz_targets/pem.rs @@ -0,0 +1,16 @@ +#![no_main] + +use std::io::BufReader; +use std::hint::black_box; + +use libfuzzer_sys::fuzz_target; + +use rustls_pki_types::pem; + +fuzz_target!(|data: &[u8]| { + for x in pem::Item::iter_from_buf(&mut BufReader::new(data)) { + let _ = black_box(x); + } + + let _ = black_box(pem::Item::from_slice(data)); +});