During a security audit of a native C application, an analyst evaluates a logging routine designed to capture user-submitted feedback. The code snippet under review is as follows:
c
void log_user_feedback(char *user_input) {
FILE *log_file = fopen("/var/log/app_feedback.log", "a");
if (log_file != NULL) {
fprintf(log_file, user_input);
fclose(log_file);
}
}
The analyst notes that input submitted directly by remote users is passed to `fprintf` as the primary formatting parameter without explicit format specifiers. Which of the following application vulnerabilities is directly present in this code?
- Format string vulnerabilityAnswer
- BSQL injection
- CHeap buffer overflow
- DImproper authorization
Answer
Format string vulnerability
The correct answer identifies a format string vulnerability. When C functions such as `printf`, `fprintf`, or `sprintf` receive user-controlled input as their format string parameter without explicit specifiers (e.g., `%s`), conversion specifiers embedded within the user data are interpreted by the formatter. This permits memory disclosure and arbitrary memory writes.
Step-by-Step Solution
Key Concept
Format String Vulnerabilities
Estimated Time:1m 15s