cybersecurity · beginner · ~15 min · safe pentest lab

Is the query built by concatenation?

Spot unsafe query construction.

Challenge

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.

Task

Implement int risky_query_build(const char *code) that returns 1 if the code snippet contains "strcat" or "sprintf", and 0 otherwise.

Input

  • code: a NUL-terminated snippet of source code the grader provides.

Output

Returns 1 if either risky function name appears, 0 otherwise.

Example

risky_query_build("sprintf(q, \"SELECT...%s\", input);")   ->   1
risky_query_build("prepare(q); bind(1, input);")           ->   0

Edge cases

  • Code that uses prepared statements / binding (no strcat/sprintf) returns 0.

Input format

A NUL-terminated source-code snippet.

Output format

1 if the snippet contains "strcat" or "sprintf"; otherwise 0.

Constraints

Substring tests for "strcat" and "sprintf".

Starter code

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