Bug 1425825

Summary: gcc -Werror=format-security -Wall not reporting errors
Product: [Fedora] Fedora Reporter: Frantisek Kluknavsky <fkluknav>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 25CC: davejohansen, jakub, jwakely, law, mpolacek
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-03-07 19:44:46 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Frantisek Kluknavsky 2017-02-22 14:25:12 UTC
Description of problem:
Combination of -Wformat and -Werror=format-security flags (or -Wall and -Werror=format-security) does not behave consistently.

Using 'gcc -Wformat -Werror=format-security' with the source file provided below reports error "format not a string literal and no format arguments" on line 7 as expected whereas 'gcc -Werror=format-security -Wformat' does not. Similar behavior can be observed with the -Wall flag instead of -Wformat.


Version-Release number of selected component (if applicable):
gcc-6.3.1-1.fc25.x86_64

How reproducible:
always

Steps to Reproduce:
1. 
$ cat formatsecurity.c 
#include <stdio.h>
int main()
{
	char message[10];
	message[0]=0;
	printf(message);
	return 0;
}

2.
$ gcc -Wall -Werror=format-security  formatsecurity.c

3.
$ gcc -Wall -Werror=format-security -Wall formatsecurity.c

4.
$ gcc -Werror=format-security -Wall formatsecurity.c

Actual results:
Error after step 2, silent run after steps 3 and 4.

Expected results:
Error message after each run of gcc. Either about vulnerable code or about wrong usage of flags. Adding -Wall should definitely not hide errors as in step 3.

Comment 1 Jakub Jelinek 2017-02-22 14:45:26 UTC
Filed upstream: PR79677.  In the mean time, use -Wformat-security -Werror=format-security instead of just -Werror=format-security and then it will work properly.

Comment 2 Frantisek Kluknavsky 2017-02-23 09:46:02 UTC
"-Wformat-security -Werror=format-security" gives "error: -Wformat-security ignored without -Wformat"
"-Wformat -Wformat-security -Werror=format-security" works.

Fun note: Fedora currently uses -Wall -Werror=format-security. While it is possible to get warnings with a right combination of flags (if you know...), it is a very strange feeling to fix rpm build errors by adding another -Wall. Surprisingly satisfying ;-)

Comment 3 Jakub Jelinek 2017-03-07 19:44:46 UTC
Fixed in F26, not going to backport.