[cfe-dev] RFC: default to -Werror=format-security
Andrey Bokhanko via cfe-dev
cfe-dev at lists.llvm.org
Tue Feb 23 13:57:37 PST 2016
Another interesting case is from gnumeric
(https://github.com/paulfitz/gnumeric/blob/master/src/tools/analysis-frequency.c,
lines 144-155):
switch (info->base.group_by) {
case GROUPED_BY_ROW:
format = _("Row %d");
break;
case GROUPED_BY_COL:
format = _("Column %d");
break;
default:
format = _("Area %d");
break;
}
dao_set_cell_printf (dao, col, 1, format, col);
("dao_set_cell_print" is just a wrapper around printf)
But we can't compile this code already! -- as gnumeric build adds
"-Werror=format=2" that turns "format string is not a string literal"
warning into an error:
analysis-frequency.c:155:38: error: format string is not a string literal
[-Werror,-Wformat-nonliteral]
dao_set_cell_printf (dao, col, 1, format, col);
^~~~~~
Yours,
Andrey
=====
Software Engineer
Intel Compiler Team
On Wed, Feb 17, 2016 at 11:48 AM, David Chisnall via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> On 16 Feb 2016, at 21:56, Aaron Ballman via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>>
>> Sorry, but printf(fmt); is *always* a true positive in my book. Same
>> with failing to return from all code paths. (etc)
>
> You are wrong. The most common reason for printf(fmt) to appear is that fmt is the result of doing a lookup of the locale-aware version of some constant string. In this case, the contents of fmt is entirely under the control of whoever shipped the application, and will have been checked for format string vulnerabilities by the localisation tools (at least, assuming that the original that is being translated are free from vulnerabilities). If you are not doing any caching in the application, then you can mark the translation function with the attribute that indicates that its input and output have the same format string compatibility. If you are caching, then there is no easy way of silencing this warning.
>
> Making this an error will cause valid and correct code to fail to compile and will result in people simply disabling the warning, rather than checking it.
>
> David
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list