Overcoming Fuzzing Obstacles
Codebases often contain anti-fuzzing patterns that prevent effective coverage. Checksums, global state (like time-seeded PRNGs), and validation checks can block the fuzzer from exploring deeper code paths. This technique shows how to patch your System Under Test (SUT) to bypass these obstacles during fuzzing while preserving production behavior.
Overview
Many real-world programs were not designed with fuzzing in mind. They may:
- Verify checksums or cryptographic hashes before processing input
- Rely on global state (e.g., system time, environment variables)
- Use non-deterministic random number generators
- Perform complex validation that makes it difficult for the fuzzer to generate valid inputs
These patterns make fuzzing difficult because:
- Checksums: The fuzzer must guess correct hash values (astronomically unlikely)
- Global state: Same input produces different behavior across runs (breaks determinism)
- Complex validation: The fuzzer spends effort hitting validation failures instead of exploring deeper code
The solution is conditional compilation: modify code behavior during fuzzing builds while keeping production code unchanged.
Key Concepts
When to Apply
Apply this technique when:
- The fuzzer gets stuck at checksum or hash verification
- Coverage reports show large blocks of unreachable code behind validation
- Code uses time-based seeds or other non-deterministic global state
- Complex validation makes it nearly impossible to generate valid inputs
- You see the fuzzer repeatedly hitting the same validation failures
Skip this technique when:
- The obstacle can be overcome with a good seed corpus or dictionary
- The validation is simple enough for the fuzzer to learn (e.g., magic bytes)
- You're doing grammar-based or structure-aware fuzzing that handles validation
- Skipping the check would introduce too many false positives
- The code is already fuzzing-friendly
Quick Reference
Step-by-Step
Step 1: Identify the Obstacle
Run the fuzzer and analyze coverage to find code that's unreachable. Common patterns:
- Look for checksum/hash verification before deeper processing
- Check for calls to
rand(),time(), orsrand()with system seeds - Find validation functions that reject most inputs
- Identify global state initialization that differs across runs
Tools to help:
- Coverage reports (see coverage-analysis technique)
- Profiling with
-fprofile-instr-generate - Manual code inspection of entry points
Step 2: Add Conditional Compilation
Modify the obstacle to bypass it during fuzzing builds.
C/C++ Example:
Rust Example:
Step 3: Verify Coverage Improvement
After patching:
- Rebuild with fuzzing instrumentation
- Run the fuzzer for a short time
- Compare coverage to the unpatched version
- Confirm new code paths are being explored
Step 4: Assess False Positive Risk
Consider whether skipping the check introduces impossible program states:
- Does code after the check assume validated properties?
- Could skipping validation cause crashes that cannot occur in production?
- Is there implicit state dependency?
If false positives are likely, consider a more targeted patch (see Common Patterns below).
Common Patterns
Pattern: Bypass Checksum Validation
Use Case: Hash/checksum blocks all fuzzer progress
Before:
After:
False positive risk: LOW - If data processing doesn't depend on checksum correctness
Pattern: Deterministic PRNG Seeding
Use Case: Non-deterministic random state prevents reproducibility
Before:
After:
False positive risk: LOW - Fuzzer can explore all code paths with fixed seed
Pattern: Careful Validation Skip
Use Case: Validation must be skipped but downstream code has assumptions
Before (Dangerous):
After (Safe):
False positive risk: MITIGATED - Provides safe defaults instead of skipping
Pattern: Bypass Complex Format Validation
Use Case: Multi-step validation makes valid input generation nearly impossible
Rust Example:
False positive risk: MEDIUM - Deserialization must handle malformed data gracefully
Advanced Usage
Tips and Tricks
Real-World Examples
OpenSSL: Uses FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION to modify cryptographic algorithm behavior. For example, in crypto/cmp/cmp_vfy.c, certain signature checks are relaxed during fuzzing to allow deeper exploration of certificate validation logic.
ogg crate (Rust): Uses cfg!(fuzzing) to skip checksum verification during fuzzing. This allows the fuzzer to explore audio processing code without spending effort guessing correct checksums.
Measuring Patch Effectiveness
After applying patches, quantify the improvement:
- Line coverage: Use
llvm-covorcargo-covto see new reachable lines - Basic block coverage: More fine-grained than line coverage
- Function coverage: How many more functions are now reachable?
- Corpus size: Does the fuzzer generate more diverse inputs?
Effective patches typically increase coverage by 10-50% or more.
Combining with Other Techniques
Obstacle patching works well with:
- Corpus seeding: Provide valid inputs that get past initial parsing
- Dictionaries: Help fuzzer learn magic bytes and common values
- Structure-aware fuzzing: Use protobuf or grammar definitions for complex formats
- Harness improvements: Better harness can sometimes avoid obstacles entirely
Anti-Patterns
Tool-Specific Guidance
libFuzzer
libFuzzer automatically defines FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION during compilation.
Integration tips:
- The macro is defined automatically; manual definition is usually unnecessary
- Use
#ifdefto check for the macro - Combine with sanitizers to detect bugs in newly reachable code
AFL++
AFL++ also defines FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION when using its compiler wrappers.
Integration tips:
- Use
afl-clang-fastorafl-clang-ltofor automatic macro definition - Persistent mode harnesses benefit most from obstacle patching
- Consider using
AFL_LLVM_LAF_ALLfor additional input-to-state transformations
honggfuzz
honggfuzz also supports the macro when building targets.
Integration tips:
- Use
hfuzz-clangorhfuzz-clang++wrappers - The macro is available for conditional compilation
- Combine with honggfuzz's feedback-driven fuzzing
cargo-fuzz (Rust)
cargo-fuzz automatically sets the fuzzing cfg option during builds.
Integration tips:
- Use
cfg!(fuzzing)for runtime checks in production builds - Use
#[cfg(fuzzing)]for compile-time conditional compilation - The fuzzing cfg is only set during
cargo fuzzbuilds, not regularcargo build - Can be manually enabled with
RUSTFLAGS="--cfg fuzzing"for testing
LibAFL
LibAFL supports the C/C++ macro for targets written in C/C++.
Integration tips:
- Define the macro manually or use compiler flags
- Works the same as with libFuzzer
- Useful when building custom LibAFL-based fuzzers
Troubleshooting
Related Skills
Tools That Use This Technique
Related Techniques
Resources
Key External Resources
OpenSSL Fuzzing Documentation
OpenSSL's fuzzing infrastructure demonstrates large-scale use of FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION. The project uses this macro to modify cryptographic validation, certificate parsing, and other security-critical code paths to enable deeper fuzzing while maintaining production correctness.
LibFuzzer Documentation on Flags Official LLVM documentation for libFuzzer, including how the fuzzer defines compiler macros and how to use them effectively. Covers integration with sanitizers and coverage instrumentation.
Rust cfg Attribute Reference
Complete reference for Rust conditional compilation, including cfg!(fuzzing) and cfg!(test). Explains compile-time vs. runtime conditional compilation and best practices.

