cybersecurity · intermediate · ~15 min

Is a sub-range valid?

Validate an offset+length against a buffer, overflow-aware.

Challenge

Implement int range_ok(int start, int len, int total) returning 1 if reading len bytes from offset start stays within total (start >= 0, len >= 0, and start + len <= total), else 0.

Starter code

int range_ok(int start, int len, int total) {
    /* TODO */
    return 0;
}

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