Skip to content

Commit

Permalink
Add fuzz target for PEM decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed Sep 19, 2024
1 parent 3db389d commit 4de5236
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ libfuzzer-sys = "0.4"

[dependencies.rustls-pki-types]
path = ".."
features = ["std"]

# Prevent this from interfering with workspaces
[workspace]
Expand All @@ -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
1 change: 1 addition & 0 deletions fuzz/corpus/pem/zen.pem
16 changes: 16 additions & 0 deletions fuzz/fuzz_targets/pem.rs
Original file line number Diff line number Diff line change
@@ -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));
});

0 comments on commit 4de5236

Please sign in to comment.