What is the vulnerability in this code? char output[20]; /* Assume data is a character array with value %200d asdf */ sprintf(output, data);
Reveal answer
Fill a bubble to check yourself
What is the vulnerability in this code? char output[20]; /* Assume data is a character array with value %200d asdf */ sprintf(output, data);
Buffer overflow
Off by one error
Format string vulnerability
No vulnerabilities are present in this code
The code has a format string vulnerability because sprintf() uses the 'data' array as the format string. If data contains format specifiers like %200d, they will be interpreted as format directives rather than literal text, potentially leaking stack data or causing crashes. Buffer overflow is not the primary issue.
sprintf(output, data) passes attacker-controlled data directly as the format string argument instead of using a fixed format like sprintf(output, "%s", data). If data contains format specifiers (like the given %200d), sprintf will interpret them, reading/writing memory or producing huge output based on attacker input — this is the classic format string vulnerability. It happens to also overflow the 20-byte buffer here, but the root vulnerability class being tested is the uncontrolled format string, not a plain buffer overflow (where the format string itself would be fixed/safe) or an off-by-one.