cybersecurity · intermediate · ~15 min · safe pentest lab
A real fuzz-target signature with the bounds-safety discipline a fuzzer will exercise.
Implement:
#include <stdint.h>
#include <stddef.h>
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
Parse the input as a stream of records:
[len:u8][type:u8][payload: len-1 bytes]
Count records whose type == 0x01. Return the count. Always return 0
on degenerate input. Must never crash on any input.
size == 0 or data == NULL → return 0.len == 0 → stop the walk, return what's been counted.len walks past size → stop the walk, return
what's been counted (do not read past data[size - 1]).len < 2 other
than the rules above.parse-bt-advertisement, but the
function signature is fixed and the failure mode is "stop counting"
not "return -1".len itself is one byte; the next
record is at off + len + 1.The fuzz-target signature is a portable contract. Match it once and every popular fuzzer can drive your parser.
A byte buffer + its length.
Non-negative count of type-0x01 records.
No crashes on any input. No allocation. No reads past data[size - 1].
#include <stdint.h>
#include <stddef.h>
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
/* TODO */
(void)data; (void)size;
return 0;
}
Returning -1 when input is bad (the fuzz target should always succeed). Reading data[off+1] before bounds-checking. Allowing len==0 to loop forever.
size 0. data NULL with size 0. Single byte. All-junk input.
O(size).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.