Skip to main content

Practice ยท 3 of 3

Open Once, Then Ask the fd

CHALLENGE
Difficulty: advanced+25 XP

POSIX. Implement int file_has_size(int fd, long want) โ€” fstat the fd (never a path) and return 1 when the file's size equals want, 0 when it differs, -1 on fstat failure. This is the TOCTOU-elimination primitive: the check is bound to the very object being used.

Back to lesson: Practice: Hardening Drills