Skip to content

Commit

Permalink
Merge pull request #38 from wiktor-k/add-fuzzing
Browse files Browse the repository at this point in the history
Add fuzzing setup for `Message::decode`
  • Loading branch information
wiktor-k authored Apr 9, 2024
2 parents cee1b09 + 00d7997 commit 2605fba
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ keywords = ["ssh", "agent", "authentication", "openssh", "async"]
categories = ["authentication", "cryptography", "encoding", "network-programming", "parsing"]
exclude = [".github"]

[workspace]
members = [".", "fuzz"]

[dependencies]
byteorder = "1.4.3"
async-trait = { version = "0.1.77", optional = true }
Expand Down
4 changes: 4 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
22 changes: 22 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "ssh-agent-lib-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
ssh-encoding = "0.2.0"

[dependencies.ssh-agent-lib]
path = ".."

[[bin]]
name = "message_decode"
path = "fuzz_targets/message_decode.rs"
test = false
doc = false
bench = false
28 changes: 28 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Fuzzing

This directory contains fuzzing targets for ssh-agent-lib.

## Setup

Install [`cargo-fuzz`](https://crates.io/crates/cargo-fuzz):

```sh
cargo install --locked cargo-fuzz
```

## Running

Select a target from the list printed by `cargo fuzz list` e.g. `message_decode`:

```sh
cargo +nightly fuzz run message_decode
```

Options that can be added to the `fuzz run` command:

- `--jobs N` - increase parallelism,
- `--sanitizer none` - disable sanitizer since ssh-agent-lib does not use any `unsafe` blocks,

Note that due to a limitation of cargo-fuzz nightly version of the toolchain is required.

For more details see [Fuzzing with cargo-fuzz](https://rust-fuzz.github.io/book/cargo-fuzz.html) or the [more detailed explanation of fuzzing output](https://github.com/rust-fuzz/cargo-fuzz/issues/72#issuecomment-284448618) in a `cargo-fuzz` comment.
9 changes: 9 additions & 0 deletions fuzz/fuzz_targets/message_decode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use ssh_agent_lib::proto::message::Message;
use ssh_encoding::Decode;

fuzz_target!(|data: &[u8]| {
let _ = Message::decode(&mut &data[..]);
});

0 comments on commit 2605fba

Please sign in to comment.