cybersecurity · intermediate · ~15 min
Recognise the TOCTOU-safe pattern.
Implement int toctou_safe(const char *approach) returning 1 for "open-then-fstat" and "use-fd" (operate on the open descriptor) and 0 for "stat-then-open" (the classic check-then-use race).
#include <string.h>
int toctou_safe(const char *approach) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.