cybersecurity · intermediate · ~15 min

Does it refuse to follow symlinks?

Recognise the symlink-refusal flag.

Challenge

Check whether an open call refuses to follow symlinks — O_NOFOLLOW makes open() fail on a symlink, blocking redirection to an unexpected target.

Task

Implement int uses_nofollow(const char *flags) that returns 1 if the open-flags string contains the substring "O_NOFOLLOW", and 0 otherwise.

Input

  • flags: a NUL-terminated open-flags string the grader provides (e.g. "O_RDONLY|O_NOFOLLOW").

Output

Returns 1 if O_NOFOLLOW is present, 0 otherwise.

Example

uses_nofollow("O_RDONLY|O_NOFOLLOW")   ->   1
uses_nofollow("O_RDONLY")              ->   0

Edge cases

  • A flags string without O_NOFOLLOW returns 0.

Input format

A NUL-terminated open-flags string flags.

Output format

1 if flags contains "O_NOFOLLOW"; otherwise 0.

Constraints

Substring test for "O_NOFOLLOW".

Starter code

#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.