cybersecurity · beginner · ~10 min
Fuzz-harness contract: allocate, NUL-terminate, call, free.
Implement int call_under_test_with_buffer(const unsigned char *data, int size, int (*parser)(const char *)).
The function:
size <= 0 or data == NULL or parser == NULL, return 0 (skip).size + 1 bytes, copy data, NUL-terminate.parser on the copy.This is the kernel of every libFuzzer harness for a string-parser.
The libFuzzer entry-point signature is muscle memory. Write it once; reuse forever.
data + size + parser callback.
0 always.
No leaks. Always NUL-terminate.
#include <stddef.h>
int call_under_test_with_buffer(const unsigned char *data, int size, int (*parser)(const char *)) { /* TODO */ (void)data; (void)size; (void)parser; return 0; }
Forgetting +1 for NUL. Leaking on the early-return path.
size == 0. NULL data. NULL parser.
O(size).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.