cybersecurity · intermediate · ~15 min
Spot characters used in SQL injection.
Flag input that contains characters commonly abused in SQL injection — an audit aid layered on top of prepared statements.
Implement int has_sql_meta(const char *s) that returns 1 if s contains a single quote ', a double quote ", a semicolon ;, or the comment marker --, and 0 otherwise.
s: a fixed NUL-terminated string the grader provides.Returns 1 if any of those metacharacters/tokens are present, 0 otherwise.
has_sql_meta("a' OR '1'='1") -> 1
has_sql_meta("admin--") -> 1
has_sql_meta("alice") -> 0
A fixed NUL-terminated string s.
1 if s contains ' " ; or --; otherwise 0.
Detection only; the proper fix is parameterised queries.
#include <string.h>
int has_sql_meta(const char *s) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.