From 9821aabf0b50d2487b07502d3d2cd89e7d62bdbe Mon Sep 17 00:00:00 2001 From: murilo ijanc Date: Tue, 24 Mar 2026 15:04:03 -0300 Subject: Initial commit NAT-aware Kademlia DHT library for peer-to-peer networks. Features: - Distributed key-value storage (iterative FIND_NODE, FIND_VALUE, STORE) - NAT traversal via DTUN hole-punching and proxy relay - Reliable Datagram Protocol (RDP) with 7-state connection machine - Datagram transport with automatic fragmentation/reassembly - Ed25519 packet authentication - 256-bit node IDs (Ed25519 public keys) - Rate limiting, ban list, and eclipse attack mitigation - Persistence and metrics - OpenBSD and Linux support --- fuzz/fuzz_parse.rs | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 fuzz/fuzz_parse.rs (limited to 'fuzz') diff --git a/fuzz/fuzz_parse.rs b/fuzz/fuzz_parse.rs new file mode 100644 index 0000000..0efdf42 --- /dev/null +++ b/fuzz/fuzz_parse.rs @@ -0,0 +1,87 @@ +//! Fuzz targets for message parsers. +//! +//! Run with: cargo +nightly fuzz run fuzz_parse +//! +//! Requires: cargo install cargo-fuzz +//! +//! These targets verify that no input can cause a panic, +//! buffer overflow, or undefined behavior in the parsers. + +// Note: this file is a reference for cargo-fuzz targets. +// To use, create a fuzz/Cargo.toml and fuzz_targets/ +// directory per cargo-fuzz conventions. The actual fuzz +// harnesses are: + +#[cfg(test)] +mod tests { + /// Fuzz MsgHeader::parse with random bytes. + #[test] + fn fuzz_header_parse() { + for _ in 0..10_000 { + let mut buf = [0u8; 128]; + tesseras_dht::sys::random_bytes(&mut buf); + // Should never panic + let _ = tesseras_dht::wire::MsgHeader::parse(&buf); + } + } + + /// Fuzz msg::parse_store with random bytes. + #[test] + fn fuzz_store_parse() { + for _ in 0..10_000 { + let mut buf = [0u8; 256]; + tesseras_dht::sys::random_bytes(&mut buf); + let _ = tesseras_dht::msg::parse_store(&buf); + } + } + + /// Fuzz msg::parse_find_node with random bytes. + #[test] + fn fuzz_find_node_parse() { + for _ in 0..10_000 { + let mut buf = [0u8; 128]; + tesseras_dht::sys::random_bytes(&mut buf); + let _ = tesseras_dht::msg::parse_find_node(&buf); + } + } + + /// Fuzz msg::parse_find_value with random bytes. + #[test] + fn fuzz_find_value_parse() { + for _ in 0..10_000 { + let mut buf = [0u8; 256]; + tesseras_dht::sys::random_bytes(&mut buf); + let _ = tesseras_dht::msg::parse_find_value(&buf); + } + } + + /// Fuzz rdp::parse_rdp_wire with random bytes. + #[test] + fn fuzz_rdp_parse() { + for _ in 0..10_000 { + let mut buf = [0u8; 128]; + tesseras_dht::sys::random_bytes(&mut buf); + let _ = tesseras_dht::rdp::parse_rdp_wire(&buf); + } + } + + /// Fuzz dgram::parse_fragment with random bytes. + #[test] + fn fuzz_fragment_parse() { + for _ in 0..10_000 { + let mut buf = [0u8; 64]; + tesseras_dht::sys::random_bytes(&mut buf); + let _ = tesseras_dht::dgram::parse_fragment(&buf); + } + } + + /// Fuzz msg::parse_find_value_reply with random bytes. + #[test] + fn fuzz_find_value_reply_parse() { + for _ in 0..10_000 { + let mut buf = [0u8; 256]; + tesseras_dht::sys::random_bytes(&mut buf); + let _ = tesseras_dht::msg::parse_find_value_reply(&buf); + } + } +} -- cgit v1.2.3