Skip to content

test(security): fuzz targets, a CI fuzz run and a replayed corpus - #331

Merged
homer6 merged 3 commits into
devfrom
security/307-fuzz
Nov 3, 2026
Merged

homer6 merged 3 commits into
devfrom
security/307-fuzz

Conversation

@homer6

@homer6 homer6 commented Nov 3, 2026

Copy link
Copy Markdown
Owner

libFuzzer targets for the security pages' parsers, a CI fuzz run, and a corpus replayed as tests (#307). Stacked on #330.

fuzz/

  • parsers.hpp: parse_port, payload and nesting, the code parsing-and-validation.md and bounds.md show.
  • targets.hpp: one target per parser that checks the page's properties (an accepted port is spelled exactly as its digits; a payload lies inside the packet; nesting is balanced and within the limit), and aborts if one breaks.
  • fuzz_*.cpp: libFuzzer entry points.
  • CMakeLists.txt: built with CPPDOCS_FUZZ=ON (root option; Clang only). -fsanitize=fuzzer,address,undefined, or fuzzer,address on Apple, where Homebrew LLVM 22's objects with UBSan fail to link with the macOS 14 system linker ("invalid r_symbolnum").
  • corpus/<target>/: seeds plus regressions. README.md explains it all.

The fuzzer found a real bug in its first 30 seconds: parse_port("05") returned 5, a second spelling of port 5. That's the ambiguity parsing-and-validation.md itself says to reject. Fixed here:

  • the parser rejects leading zeros, on the page, in its test ("080", "05" added) and in parsers.hpp;
  • the page says the fuzz target found it;
  • corpus/parse_port/leading-zero keeps the input.

After the fix, 60 s and 89 M runs found nothing.

Replay test: tests/security/fuzz_corpus_test.cpp replays every saved input through the same targets on every platform and compiler, without libFuzzer. It gets the corpus path and include directory from tests/CMakeLists.txt (security area only).

CI:

  • New fuzz job in linux.yml: Clang 22 from apt.llvm.org, runs when the tests do, 120 s per target via the new tools/ci/fuzz.sh, and uploads failing inputs.
  • linux-toolchain.sh installs libclang-rt-<ver>-dev for CPPDOCS_FUZZ too.
  • check_workflows.py: OK.

Tested

  • security area: gcc-15 66/66, clang-22 66/66, gcc-16 66/66.
  • Fuzz targets built with Clang 22; each fuzzed locally: 30 s each first (found the bug), then 60 s on parse_port after the fix, then tools/ci/fuzz.sh 5 end to end.
  • Parsing page snippets: GCC 15 and Clang 22, 5 checked, 0 failed. Links ok.

Docs: fuzz/README.md; docs/testing.md "Fuzzing (#307)"; a CLAUDE.md "Fuzzing" paragraph (crash → fix → minimized input in the corpus); the workflows README; a README.md pointer to fuzz/.

Related to #307, #286

@homer6
homer6 force-pushed the security/300-hardening-page branch from 53a3b10 to ffa3f6e Compare November 3, 2026 12:23
@homer6
homer6 force-pushed the security/307-fuzz branch from 68b0046 to 6ee2c73 Compare November 3, 2026 12:23
@homer6
homer6 changed the base branch from security/300-hardening-page to dev November 3, 2026 13:09
@homer6
homer6 merged commit 92de0cd into dev Nov 3, 2026
@homer6
homer6 deleted the security/307-fuzz branch November 3, 2026 13:18
@homer6

homer6 commented Nov 3, 2026

Copy link
Copy Markdown
Owner Author

Merged into dev as a merge commit (92de0cd) on the owner's review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant