From d760e844bb03dbcba07cc88c6f12217f8aa8450a Mon Sep 17 00:00:00 2001 From: Louis Merlin Date: Mon, 20 Nov 2023 14:19:17 +0100 Subject: [PATCH] Add first version of cmplog testing --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + examples/cmplog/.gitignore | 2 ++ examples/cmplog/Cargo.toml | 8 ++++++++ examples/cmplog/README.md | 13 +++++++++++++ examples/cmplog/src/main.rs | 38 +++++++++++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+) create mode 100644 examples/cmplog/.gitignore create mode 100644 examples/cmplog/Cargo.toml create mode 100644 examples/cmplog/README.md create mode 100644 examples/cmplog/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index b08b3a6..2182d43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -178,6 +178,13 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" +[[package]] +name = "cmplog-fuzz" +version = "0.1.0" +dependencies = [ + "ziggy", +] + [[package]] name = "colorchoice" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index db9a443..06c3962 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ repository = "https://github.com/srlabs/ziggy/" members = [ ".", "examples/arbitrary", + "examples/cmplog", "examples/url", ] diff --git a/examples/cmplog/.gitignore b/examples/cmplog/.gitignore new file mode 100644 index 0000000..3dd5509 --- /dev/null +++ b/examples/cmplog/.gitignore @@ -0,0 +1,2 @@ +output +Cargo.lock \ No newline at end of file diff --git a/examples/cmplog/Cargo.toml b/examples/cmplog/Cargo.toml new file mode 100644 index 0000000..02630d6 --- /dev/null +++ b/examples/cmplog/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "cmplog-fuzz" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +ziggy = { path = "../../", default-features = false } diff --git a/examples/cmplog/README.md b/examples/cmplog/README.md new file mode 100644 index 0000000..9362e9c --- /dev/null +++ b/examples/cmplog/README.md @@ -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 +``` diff --git a/examples/cmplog/src/main.rs b/examples/cmplog/src/main.rs new file mode 100644 index 0000000..690d7ef --- /dev/null +++ b/examples/cmplog/src/main.rs @@ -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"); + }); +} \ No newline at end of file