You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|[`-Wimplicit-fallthrough`](#-Wimplicit-fallthrough)| GCC 7<br>Clang 4.0 | Warn when a switch case falls through |
187
188
|[`-Wbidi-chars=any`](#-Wbidi-chars=any)| GCC 12 | Enable warnings for possibly misleading Unicode bidirectional control characters |
188
189
|[`-Werror`](#-Werror)<br/>[`-Werror=`*`<warning-flag>`*](#-Werror-flag)| GCC 2.95.3<br/>Clang 2.6 | Treat all or selected compiler warnings as errors. Use the blanket form `-Werror` only during development, not in source distribution. |
190
+
|[`-Werror=format-security`](#-Werror=format-security)| GCC 2.95.3<br/>Clang 4.0 | Treat format strings that are not string literals and used without arguments as errors |
189
191
|[`-Werror=implicit`](#-Werror=implicit)<br/>[`-Werror=incompatible-pointer-types`](#-Werror=incompatible-pointer-types)<br/>[`-Werror=int-conversion`](#-Werror=int-conversion)<br/> | GCC 2.95.3<br/>Clang 2.6 | Treat obsolete C constructs as errors |
190
192
191
193
Table 2: Recommended compiler options that enable run-time protection mechanisms.
@@ -399,6 +401,44 @@ Zero-warning policies can also be enforced at CI level. CI-based zero- or bounde
399
401
400
402
---
401
403
404
+
### Treat format strings that are not string literals and used without arguments as errors
| <spanid="-Werror=format-security">`-Werror=format-security`</span> | GCC 2.95.3<br/> Clang 4.0 | Treat format strings that are not string literals and used without arguments as errors |
409
+
410
+
#### Synopsis
411
+
412
+
Treat calls to printf- and scanf-family of functions where the format string is not a string literal and there are no additional format arguments as errors.
413
+
414
+
Format strings that can be influenced at run-time from outside the program are likely to cause format string vulnerabilities[^scut2001]. We recommend treating format strings that are not string literals and used without addition arguments as errors as invocations of the form:
415
+
416
+
~~~C
417
+
printf(fmt);
418
+
printf(gettext("Hello World\n"));
419
+
fprintf(stderr, fmt);
420
+
~~~
421
+
422
+
always indicates a bug and, if the format string can be controlled by external input, can be used in a format string attack. Code of this form where the format string `fmt` is not expected to contain format specifiers can be rewritten in a safe form using a fixed format string:
423
+
424
+
~~~C
425
+
printf("%s", fmt);
426
+
printf("%s", gettext("Hello World\n"));
427
+
fprintf(stderr, "%s", fmt);
428
+
~~~
429
+
430
+
Some Linux distributions, such as Arch Linux[^arch-buildflags], Fedora[^fedora-formatsecurityfaq], and Ubuntu[^ubuntu-compilerflags], are enforcing the use of `-Werror=format-security` when building software for distribution.
431
+
432
+
[^scut2001]: scut \[TESO\], [Exploiting Format String Vulnerabilities](https://web.archive.org/web/20240402183013/https://cs155.stanford.edu/papers/formatstring-1.2.pdf), version 1.2, 2001-09-01.
0 commit comments