cybersecurity · beginner · ~15 min · safe pentest lab
Spot unsafe query construction.
Spot code that builds a SQL string by concatenation — using strcat or sprintf to splice user input into query text is the root cause of SQL injection.
Implement int risky_query_build(const char *code) that returns 1 if the code snippet contains "strcat" or "sprintf", and 0 otherwise.
code: a NUL-terminated snippet of source code the grader provides.Returns 1 if either risky function name appears, 0 otherwise.
risky_query_build("sprintf(q, \"SELECT...%s\", input);") -> 1
risky_query_build("prepare(q); bind(1, input);") -> 0
strcat/sprintf) returns 0.A NUL-terminated source-code snippet.
1 if the snippet contains "strcat" or "sprintf"; otherwise 0.
Substring tests for "strcat" and "sprintf".
#include <string.h>
int risky_query_build(const char *code) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.