cybersecurity · intermediate · ~15 min · safe pentest lab
Validate every slice against the fuzz input.
Validate that a slice read stays inside the fuzzer's buffer, so the fuzzer can't trigger an out-of-bounds read.
Implement int read_within(int offset, int len, int size) that returns 1 if reading len bytes starting at offset stays within size, else 0.
The read is in bounds when offset >= 0, len >= 0, and offset + len <= size.
offset: the start position of the read.len: the number of bytes to read.size: the total buffer length.Returns int: 1 if the read is fully in bounds, else 0.
read_within(4, 8, 16) -> 1
read_within(12, 8, 16) -> 0 (12 + 8 > 16)
read_within(-1, 4, 16) -> 0 (negative offset)
offset or len is out of bounds (return 0).size is in bounds.Three ints: offset, len, and the buffer size.
An int: 1 if the slice is fully in bounds, else 0.
In bounds iff offset>=0, len>=0, and offset+len<=size.
int read_within(int offset, int len, int size) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.