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 27, 2024
1 parent eba17af commit 0e9df2e
Show file tree
Hide file tree
Showing 4 changed files with 35 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
26 changes: 26 additions & 0 deletions fuzz/fuzz_targets/pem.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#![no_main]

use std::io::Cursor;

use libfuzzer_sys::fuzz_target;

use rustls_pki_types::pem::PemObject;
use rustls_pki_types::{CertificateDer, PrivateKeyDer};

fuzz_target!(|data: &[u8]| {
// cover the code paths that use std::io
for x in CertificateDer::pem_reader_iter(&mut Cursor::new(data)) {
match x {
Ok(_item) => (),
Err(_err) => break,
}
}

// cover the code paths that use slices
for x in PrivateKeyDer::pem_slice_iter(data) {
match x {
Ok(_item) => (),
Err(_err) => break,
}
}
});

0 comments on commit 0e9df2e

Please sign in to comment.