mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-29 08:59:31 +00:00
- Use std::sync::LazyLock to construct Sanitizer, Validator, and LeakDetector once instead of on every fuzz iteration (they compile regex/Aho-Corasick) - Remove fuzz_config_env assertion that panics on null-byte-only input - Remove no-op length check with misleading comment in fuzz_config_env - Update fuzz_config_env description in README to match actual behavior Co-Authored-By: Claude Opus 4.6 <[email protected]>
26 lines
893 B
Rust
26 lines
893 B
Rust
#![no_main]
|
|
use libfuzzer_sys::fuzz_target;
|
|
use std::sync::LazyLock;
|
|
|
|
use ironclaw::safety::Validator;
|
|
use ironclaw::tools::validate_tool_schema;
|
|
|
|
static VALIDATOR: LazyLock<Validator> = LazyLock::new(Validator::new);
|
|
|
|
fuzz_target!(|data: &[u8]| {
|
|
if let Ok(s) = std::str::from_utf8(data) {
|
|
// Try parsing as JSON and validating as tool parameters
|
|
if let Ok(value) = serde_json::from_str::<serde_json::Value>(s) {
|
|
// Exercise Validator::validate_tool_params with arbitrary JSON
|
|
let result = VALIDATOR.validate_tool_params(&value);
|
|
// Invariant: result should always be well-formed
|
|
if !result.is_valid {
|
|
assert!(!result.errors.is_empty());
|
|
}
|
|
|
|
// Exercise validate_tool_schema with arbitrary JSON as a schema
|
|
let _ = validate_tool_schema(&value, "fuzz");
|
|
}
|
|
}
|
|
});
|