cybersecurity · intermediate · ~15 min
Recognise the symlink-refusal flag.
Check whether an open call refuses to follow symlinks — O_NOFOLLOW makes open() fail on a symlink, blocking redirection to an unexpected target.
Implement int uses_nofollow(const char *flags) that returns 1 if the open-flags string contains the substring "O_NOFOLLOW", and 0 otherwise.
flags: a NUL-terminated open-flags string the grader provides (e.g. "O_RDONLY|O_NOFOLLOW").Returns 1 if O_NOFOLLOW is present, 0 otherwise.
uses_nofollow("O_RDONLY|O_NOFOLLOW") -> 1
uses_nofollow("O_RDONLY") -> 0
O_NOFOLLOW returns 0.A NUL-terminated open-flags string flags.
1 if flags contains "O_NOFOLLOW"; otherwise 0.
Substring test for "O_NOFOLLOW".
#include <string.h>
int uses_nofollow(const char *flags) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.