Potential problem
In /cgi-bin/ipp-var.c the value filter_value is compared against NULL at line 1290, and later, at line 1332, it is passed as the second argument to _cups_strcasecmp() when matching an IPP attribute value.
https://github.com/OpenPrinting/cups/blob/master/cgi-bin/ipp-var.c#L1332
https://github.com/OpenPrinting/cups/blob/master/cups/string.c#L1051
At the same time we check that filter_value is not NULL at line 1290, but the problem is, that this check is separated from the point of use by the whole loop body, and between them the value is not re-validated before being dereferenced. The static analyzer reports:
After having been compared to a NULL value at ipp-var.c:1290, pointer 'filter_value' is passed as 2nd parameter in call to function '_cups_strcasecmp' at ipp-var.c:1332, where it is dereferenced at string.c:1051.
Inside _cups_strcasecmp() the second argument is dereferenced in the loop condition *t != '\0':
_cups_strcasecmp(const char *s, /* I - First string */
const char *t) /* I - Second string */
{
int diff;
while (*s != '\0' && *t != '\0')
{
diff = _cups_tolower(*s) - _cups_tolower(*t);
...
This means that a situation may arise in which filter_value is NULL at the moment of the call, and the program will not have time to react, and we will dereference a NULL pointer inside _cups_strcasecmp(), which can lead to unpredictable results.
Possible solution
Given that in your implementation of the code, filter_value is used only inside the condition that already checks filter->values[0].string.text for NULL, the problem can be solved by simply adding one more NULL check to the conditional expression right before the _cups_strcasecmp() call:
filter->values[0].string.text != NULL &&
filter_value != NULL &&
!_cups_strcasecmp(filter->values[0].string.text, filter_value))
In that case the existing line 1332 (!_cups_strcasecmp(...)) shifts to line 1333, and _cups_strcasecmp() is never called with a NULL second argument.
Found by Linux Verification Center (portal.linuxtesting.ru (https://portal.linuxtesting.ru/)) with SVACE.
Author D. Babushkin.
Potential problem
In /cgi-bin/ipp-var.c the value filter_value is compared against NULL at line 1290, and later, at line 1332, it is passed as the second argument to _cups_strcasecmp() when matching an IPP attribute value.
https://github.com/OpenPrinting/cups/blob/master/cgi-bin/ipp-var.c#L1332
https://github.com/OpenPrinting/cups/blob/master/cups/string.c#L1051
At the same time we check that filter_value is not NULL at line 1290, but the problem is, that this check is separated from the point of use by the whole loop body, and between them the value is not re-validated before being dereferenced. The static analyzer reports:
After having been compared to a NULL value at ipp-var.c:1290, pointer 'filter_value' is passed as 2nd parameter in call to function '_cups_strcasecmp' at ipp-var.c:1332, where it is dereferenced at string.c:1051.
Inside _cups_strcasecmp() the second argument is dereferenced in the loop condition *t != '\0':
This means that a situation may arise in which filter_value is NULL at the moment of the call, and the program will not have time to react, and we will dereference a NULL pointer inside _cups_strcasecmp(), which can lead to unpredictable results.
Possible solution
Given that in your implementation of the code, filter_value is used only inside the condition that already checks filter->values[0].string.text for NULL, the problem can be solved by simply adding one more NULL check to the conditional expression right before the _cups_strcasecmp() call:
In that case the existing line 1332 (!_cups_strcasecmp(...)) shifts to line 1333, and _cups_strcasecmp() is never called with a NULL second argument.
Found by Linux Verification Center (portal.linuxtesting.ru (https://portal.linuxtesting.ru/)) with SVACE.
Author D. Babushkin.