cybersecurity · intermediate · ~15 min
Recognise the atomic-create defence.
Check whether an open call requests atomic creation — O_CREAT|O_EXCL fails if the file already exists, closing the create-time TOCTOU window.
Implement int uses_excl(const char *flags) that returns 1 if the open-flags string contains the substring "O_EXCL", and 0 otherwise.
flags: a NUL-terminated open-flags string the grader provides (e.g. "O_CREAT|O_EXCL|O_WRONLY").Returns 1 if O_EXCL is present, 0 otherwise.
uses_excl("O_CREAT|O_EXCL|O_WRONLY") -> 1
uses_excl("O_CREAT|O_WRONLY") -> 0
O_EXCL returns 0.A NUL-terminated open-flags string flags.
1 if flags contains "O_EXCL"; otherwise 0.
Substring test for "O_EXCL".
#include <string.h>
int uses_excl(const char *flags) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.