cybersecurity · intermediate · ~15 min

Escape single quotes

Implement SQL single-quote escaping safely.

Challenge

As a last resort, implement int escape_quotes(const char *in, char *out, int outsz) doubling every single quote (' -> ''), NUL-terminating, and returning the output length, or -1 if it wouldn't fit.

Starter code

int escape_quotes(const char *in, char *out, int outsz) {
    /* TODO */
    return -1;
}

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