cybersecurity · intermediate · ~15 min

Bounds-safe byte read for a fuzzer

Defend every access against the fuzzer's arbitrary size.

Challenge

A fuzz target gets arbitrary data/size. Implement int safe_byte(const unsigned char *data, int size, int idx) returning data[idx] if 0 <= idx < size, else -1 — so the parser never reads out of bounds.

Starter code

int safe_byte(const unsigned char *data, int size, int idx) {
    /* TODO */
    return -1;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.