cybersecurity · intermediate · ~15 min

Detect shell metacharacters

Spot characters that break out of a shell command.

Challenge

Implement int has_shell_meta(const char *s) returning 1 if s contains any of these shell metacharacters: ; | & $ ` ( ) < > newline, else 0.

Starter code

#include <string.h>

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

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