cybersecurity · intermediate · ~15 min

Allowlist a safe argument

Allowlist instead of blocklist for command arguments.

Challenge

Implement int is_safe_arg(const char *s) returning 1 if s is non-empty and contains only letters, digits, '.', '-', '_', '/', else 0 (an allowlist for a filename-like argument).

Starter code

int is_safe_arg(const char *s) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.