Skip to content

Commit

Permalink
Add first version of cmplog testing
Browse files Browse the repository at this point in the history
  • Loading branch information
louismerlin committed Nov 20, 2023
1 parent bc95be6 commit d760e84
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repository = "https://github.com/srlabs/ziggy/"
members = [
".",
"examples/arbitrary",
"examples/cmplog",
"examples/url",
]

Expand Down
2 changes: 2 additions & 0 deletions examples/cmplog/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
output
Cargo.lock
8 changes: 8 additions & 0 deletions examples/cmplog/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "cmplog-fuzz"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
ziggy = { path = "../../", default-features = false }
13 changes: 13 additions & 0 deletions examples/cmplog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Ziggy example - CMPLOG

First, install the tooling:

```
cargo install cargo-afl honggfuzz ziggy
```

Then, in this directory, run:

```
cargo ziggy fuzz
```
38 changes: 38 additions & 0 deletions examples/cmplog/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
fn main() {
// This fuzz harness demonstrates the capabilities of CmpLog.
// Simply run the fuzzer and it should find the crash immediately.
ziggy::fuzz!(|data: &[u8]| {
if data.len() < 29 {
return;
}
if data[0] != b'A' {
return;
}
if data[1] != b'B' {
return;
}
if data[2] != b'C' {
return;
}
if data[3] != b'D' {
return;
}

if data[4..8] != 0x6969_4141_i32.to_le_bytes() {
return;
};

if data[8..12] != *b"1234" || data[12..16] != *b"EFGH" {
return;
};

let slice = &data[16..];
let match_string = "Hello, world!";
let compare_string = String::from_utf8(slice.to_vec()).unwrap_or_default();
if compare_string != match_string {
return;
}

panic!("BOOM");
});
}

0 comments on commit d760e84

Please sign in to comment.