Skip to content

Commit

Permalink
fuzz: add target for LocalAddress from string (#227)
Browse files Browse the repository at this point in the history
* fuzz: add target for `LocalAddress` from string

* docs: add fuzzing into README
  • Loading branch information
brunoerg authored Sep 3, 2024
1 parent 3eb0445 commit bf01bef
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 12 deletions.
26 changes: 26 additions & 0 deletions Cargo.lock

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

13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
[workspace]
resolver = "2"
members = [
"florestad",
"fuzz",
"crates/floresta",
"crates/floresta-chain",
"crates/floresta-cli",
"crates/floresta-common",
"crates/floresta-compact-filters",
"crates/floresta-electrum",
"crates/floresta-watch-only",
"crates/floresta-wire",
]

default-members = [
"florestad",
"crates/floresta",
"crates/floresta-chain",
Expand Down
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ If you want to use `libfloresta` to build your own Bitcoin application, you can

### ToC

- [Community](#community)
- [Building](#building)
- [(Prerequisites)](#prerequisites)
- [Building with nix](#building-with-nix)
- [Running](#running)
- [Assume Utreexo](#assume-utreexo)
- [Compact Filters](#compact-filters)
- [Getting help](#getting-help)
- [Wallet](#wallet)
- [Running the tests](#running-the-tests)
- [Contributing](#contributing)
- [Using Nix](#using-nix)
- [License](#license)
- [Acknowledgments](#acknowledgments)
- [Consensus implementation](#consensus-implementation)
- [Running](#running)
- [Assume Utreexo](#assume-utreexo)
- [Compact Filters](#compact-filters)
- [Getting help](#getting-help)
- [Wallet](#wallet)
- [Running the tests](#running-the-tests)
- [Requirements](#requirements)
- [Fuzzing](#fuzzing)
- [Contributing](#contributing)
- [Using Nix](#using-nix)
- [License](#license)
- [Acknowledgments](#acknowledgments)
- [Consensus implementation](#consensus-implementation)

### Community

Expand Down Expand Up @@ -203,6 +205,15 @@ pip3 install -r tests/requirements.txt
python tests/run_tests.py
```

### Fuzzing

This project uses `cargo-fuzz` (libfuzzer) for fuzzing, you can run a fuzz target with:
```bash
cargo +nightly fuzz run local_address_str
```

You can replace `local_address_str` with the name of any other target you want to run.

### Contributing
Contributions are welcome, feel free to open an issue or a pull request.

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
20 changes: 20 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "floresta-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
bitcoin = { version = "0.31", features = ["serde", "std"] }
floresta-wire = { path = "../crates/floresta-wire" }

[[bin]]
name = "local_address_str"
path = "fuzz_targets/local_address_str.rs"
test = false
doc = false
bench = false
14 changes: 14 additions & 0 deletions fuzz/fuzz_targets/local_address_str.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![no_main]

use core::str;
use std::str::FromStr;

use floresta_wire::address_man::LocalAddress;
use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
let _ = match str::from_utf8(data) {
Ok(s) => LocalAddress::from_str(s),
Err(_) => return,
};
});

0 comments on commit bf01bef

Please sign in to comment.