Secure Coding in C · intermediate · ~15 min
Write a function with libFuzzer's `LLVMFuzzerTestOneInput` signature that parses a record stream without crashing.
Same TLV-walk discipline as parse-bt-advertisement, lifted into libFuzzer's standard entry-point signature.
The fuzz-target shape is a portable contract. Once your code matches it, every popular fuzzer can drive it.
A fuzz target is a single function. libFuzzer, AFL++, Honggfuzz — all the popular fuzzers drive their target via:
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
The contract:
data / size without crashing.We're not running a real fuzzer in the harness. We're writing the shape of a defensive target and proving it survives edge inputs.
[ len : u8 ][ type : u8 ][ payload : len - 1 bytes ]
The fuzz target counts records whose type == 0x01. Edge cases that
must NOT crash:
size == 0 → return 0data == NULL (with size 0) → return 0len walks past size → stop counting, return what we
have so far (no read past end).len == 0 → stop (would loop forever).Implement int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
that walks the record stream, never reads past size, returns the
count of type-0x01 records.
len before advancing.len == 0 to spin.LLVMFuzzerTestOneInput, bounds-checked TLV walk, no allocation, never crash.