Closed frostb1ten closed 1 week ago
Note: Not treating as a security issue because debug printfs are a developer tool that is not normally compiled into the library.
CUPS_DEBUG_LOG
is defined as supporting only a single "%d" to insert the current process ID. Update the code to look for this and substitute manually rather than using snprintf
to do the heavy lifting.
Oh, and thank you for finding and reporting this issue... :)
[master 0da38a5f7] Harden debug printf PID support (Issue #1066)
Description A format string vulnerability exists in CUPS when compiled with debugging enabled. The vulnerability arises from improper sanitization of the CUPS_DEBUG_LOG environment variable in the _cups_debug_set() function. Specifically, this variable is passed to snprintf() without validation, allowing user input with format specifiers (e.g., %p, %n) to be processed.
This can lead to:
This finding was originally discovered while reviewing the code at: https://github.com/OpenPrinting/cups/blob/master/cups/debug.c#L98:
In this code, the CUPS_DEBUG_LOG environment variable is passed to the _cups_debug_set() function, which processes the environment data. The vulnerability occurs when the function then reaches the following line: https://github.com/OpenPrinting/cups/blob/master/cups/debug.c#L278:
Here, snprintf() is used to format the log file string, which can lead to a format string vulnerability if user-controlled input contains specifiers like %p or %n. This allows an attacker to leak memory addresses or attempt arbitrary memory writes in environments where protections like %n blocking may not be in place.
To Reproduce Steps to reproduce the behavior:
Expected behavior The CUPS_DEBUG_LOG variable should be treated as a plain string, and any format specifiers should not be interpreted by snprintf(). The log file should be created without leaking memory addresses or allowing unintended memory writes.
System Information: