test: fuzz the HTTP and PROXY v2 parsers, make PROXY parsing pure
- PROXY v2 header parsing is now the pure, total function `parse_v2_header(buf, limit) -> (SocketAddr, consumed)`; the async reader only reads bytes and delegates. This makes the parser reachable from tests and fuzz targets and keeps every index bounds-checked. - tests/proxy_v2_parser.rs: valid v4/v6 headers, bad signature, non-PROXY command, TLVs, every truncated prefix, oversized header, unsupported family, short address block, and a deterministic sweep over family/length. - fuzz/: cargo-fuzz targets `http_head` (scan_head + evaluate) and `proxy_v2` with invariants (no panic, no out-of-buffer consumption, family matches the header). Seeds for the HTTP head keep coverage useful; `make fuzz` runs 60 s per target. Both targets ran clean (7M and 3M executions). - docs/testing.md documents the fuzz workflow; .gitignore covers the generated corpus/artifacts.
This commit is contained in:
parent
da87d2a11f
commit
08b7292ac4
289 changed files with 4837 additions and 31 deletions
|
|
@ -62,6 +62,35 @@ TCP-payload по `ip->tot_len`), VLAN/QinQ-теги и фрагменты — з
|
|||
|
||||
---
|
||||
|
||||
## 3. Fuzzing
|
||||
|
||||
Внешние парсеры (HTTP request-head и PROXY protocol v2) фаззятся через `cargo-fuzz`.
|
||||
Нужен nightly-тулчейн и установленный `cargo-fuzz`:
|
||||
|
||||
```bash
|
||||
rustup toolchain install nightly
|
||||
cargo install cargo-fuzz
|
||||
|
||||
# короткий прогон (60 с на цель), как в CI-смоуке
|
||||
make fuzz
|
||||
|
||||
# длительная кампания локально
|
||||
cargo +nightly fuzz run http_head fuzz/seeds/http_head -- -max_total_time=600
|
||||
cargo +nightly fuzz run proxy_v2 -- -max_total_time=600
|
||||
```
|
||||
|
||||
Найденный краш сохраняется в `fuzz/artifacts/<target>/`; воспроизведение —
|
||||
`cargo +nightly fuzz run <target> fuzz/artifacts/<target>/<file>`. Цели лежат в
|
||||
`fuzz/fuzz_targets/`, сиды — в `fuzz/seeds/` (каталоги `corpus/`, `artifacts/`
|
||||
в git не попадают).
|
||||
|
||||
Инварианты, которые проверяют цели: парсер не паникует на произвольных байтах,
|
||||
`scan_head` не выходит за буфер, `parse_v2_header` не потребляет больше
|
||||
переданного и не принимает заголовок выше лимита, семейство адреса совпадает с
|
||||
байтом family.
|
||||
|
||||
---
|
||||
|
||||
## 3. Локальный integration-стенд (Docker)
|
||||
|
||||
```bash
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue