Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 1037051 - elfutils FTBFS if "-Werror=format-security" flag is used
Summary: elfutils FTBFS if "-Werror=format-security" flag is used
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: elfutils
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Mark Wielaard
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1038083
TreeView+ depends on / blocked
 
Reported: 2013-12-03 03:00 UTC by Dhiru Kholia
Modified: 2014-05-10 20:17 UTC (History)
11 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-05-10 20:17:16 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Dhiru Kholia 2013-12-03 03:00:49 UTC
Description of problem
----------------------

elfutils fails to build if "-Werror=format-security" flag is used.

...

cc1: error: -Wformat-security ignored without -Wformat [-Werror=format-security]

...

We are working on a proposal to enable "-Werror=format-security" for all
packages. Once this flag is enabled, GCC will refuse to compile code that could
be vulnerable to a string format security flaw. For more details, please see
https://fedorahosted.org/fesco/ticket/1185 page.

To understand why it is important to fix this, please see
https://fedoraproject.org/wiki/Format-Security-FAQ page.

How to fix this
---------------

The fix for these errors is quite simple. It's a matter of changing a
line like,

   printf(foo);

to read,

   printf("%s", foo);

That's it.

Please fix this issue in rawhide with a patch (which you should submit
to upstream to merge moving forward). Please do a new build with the
fix in rawhide. Other releases do not need to be directly fixed, but
there should be no harm in pushing out this fix/patch with other needed
changes to those branches.

In the event you don't fix this bug before the next mass rebuild,
provenpackagers may step in and update your package(s) to fix this
issue.

How reproducible
----------------

Build elfutils-0.157-2.fc21.src.rpm with "-Werror=format-security" flag to reproduce the problem.

To make this process easier, you can use a modified "redhat-rpm-config" package
from http://people.fedoraproject.org/~halfie/artifacts/redhat-rpm-config/ URL.

$ sha256sum redhat-rpm-config-9.1.0-56.fc20.*
faad7594b2080fe76497d0ce50808c905a93dd7b41c1defdde5ca57e3833d3d2  redhat-rpm-config-9.1.0-56.fc20.noarch.rpm
5aa9357174305c7285ffdbc92d7ffe1c07a8a95d5459b930461308f5aad75413  redhat-rpm-config-9.1.0-56.fc20.src.rpm

Comment 1 Mark Wielaard 2013-12-03 07:00:51 UTC
(In reply to Dhiru Kholia from comment #0)
> elfutils fails to build if "-Werror=format-security" flag is used.
> 
> ...
> 
> cc1: error: -Wformat-security ignored without -Wformat
> [-Werror=format-security]
> 
> ...
> 
> Please fix this issue in rawhide with a patch (which you should submit
> to upstream to merge moving forward). Please do a new build with the
> fix in rawhide. Other releases do not need to be directly fixed, but
> there should be no harm in pushing out this fix/patch with other needed
> changes to those branches.
> 
> In the event you don't fix this bug before the next mass rebuild,
> provenpackagers may step in and update your package(s) to fix this
> issue.

Help with fixes that are acceptable upstream would be very appreciated since the given trivial example doesn't seem to match the patterns used in elfutils. So it is not as trivial as the example makes it out. See for some discussion of the issue to resolve this fedora devel thread https://lists.fedoraproject.org/pipermail/devel/2013-November/192309.html (no replies or suggestions yet).

Comment 2 Petr Machata 2013-12-03 23:15:55 UTC
Well, we already snip -Wall from RPM_OPT_FLAGS.  We can just as well snip out the -Werror=format-security bit as well, on the grounds that we enable it again through the build system anyway, where relevant.

Comment 3 Mark Wielaard 2013-12-04 09:19:06 UTC
> Well, we already snip -Wall from RPM_OPT_FLAGS.  We can just as well snip
> out the -Werror=format-security bit as well, on the grounds that we enable
> it again through the build system anyway, where relevant.

Agreed. That would be the simplest.

Another would be to explicitly mark the places in the code with:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-security"
[... code ...]
#pragma GCC diagnostic pop

But if there is a more clean way that would be nice.(In reply to Petr Machata from comment #2)

Comment 4 Mark Wielaard 2013-12-19 20:39:35 UTC
0.157-4 Remove -Werror=format-security from RPM_OPT_FLAGS.

diff --git a/elfutils.spec b/elfutils.spec
index c41e98d..c139c19 100644
--- a/elfutils.spec
+++ b/elfutils.spec
@@ -231,7 +231,11 @@ find . -name \*.sh ! -perm -0100 -print | xargs chmod +x
 # Remove -Wall from default flags.  The makefiles enable enough warnings
 # themselves, and they use -Werror.  Appending -Wall defeats the cases where
 # the makefiles disable some specific warnings for specific code.
+# Also remove -Werror=format-security which doesn't work without
+# -Wformat (enabled by -Wall). We enable -Wformat explicitly for some
+# files later.
 RPM_OPT_FLAGS=${RPM_OPT_FLAGS/-Wall/}
+RPM_OPT_FLAGS=${RPM_OPT_FLAGS/-Werror=format-security/}
 
 %if %{compat}
 # Some older glibc headers can run afoul of -Werror all by themselves.

Comment 5 Mark Wielaard 2014-01-23 15:27:36 UTC
Proposed upstream patch:
https://lists.fedorahosted.org/pipermail/elfutils-devel/2014-January/003783.html

Comment 7 Mark Wielaard 2014-05-10 20:17:16 UTC
This has been worked around in fedora since 0.157-4 Remove -Werror=format-security from RPM_OPT_FLAGS. And upstream now explicitly builds with -Wformat=2 which includes -Wformat-security.

commit f48eb6b15fee66e54b488d71738979fc608f25ee
Author: Mark Wielaard <mjw>
Date:   Thu Jan 23 00:56:41 2014 +0100

    Use -Wformat=2 by default for all files.
    
    This just makes sure that all format strings are given as literals to
    printf like functions so the compiler can see and check them. Remove
    all no_Wformat, add -Wformat=2 unconditionally to AM_CFLAGS.
    
    Signed-off-by: Mark Wielaard <mjw>


Note You need to log in before you can comment on or make changes to this bug.