TresysTechnology/setools — pull request #1 by fishilico (2014-11-01 13:47:27+00:00)
Title: Fix gcc warnings in libqpol

Hello,

I tried builing setools 4.0.0-alpha with custom ("hardening") flags in ``setup.py`` (like what I did for SELinux userspace tools and library a few months ago, http://marc.info/?l=selinux&m=141073113518665&w=2). gcc reported many errors and this pull request is an attempt to fix them. Please review and comment the patches.

While working on these patches I discovered two bugs in libqpol: an incorrect format string with %S instead of %s and a typo in a variable name in qpol_policy_get_genfscon_by_name ("errno = errno"...). This PR includes patches which fix these bugs. These bugs are also present in the latest release of setools3.

After applying this PR, setools is building successfully with this patch to add some flags to gcc 4.9.1 to ``setup.py``:

```diff
--- a/setup.py
+++ b/setup.py
@@ -91,6 +91,28 @@ ext_py_mods = [Extension('setools.policyrep._qpol',
'libqpol/policy_scan.c'],
include_dirs=['libqpol', 'libqpol/include'],
libraries=['bz2', 'selinux', 'sepol'],
+ extra_compile_args=[
+ '-Werror', '-Wextra',
+ '-Waggregate-return',
+ '-Wcast-align',
+ '-Wfloat-equal',
+ '-Wformat', '-Wformat=2',
+ '-Winit-self',
+ '-Winline',
+ '-Wmissing-format-attribute',
+ '-Wmissing-include-dirs',
+ '-Wnested-externs',
+ '-Wold-style-definition',
+ '-Wpointer-arith',
+ '-Wredundant-decls',
+ '-Wstrict-prototypes',
+ '-Wunknown-pragmas',
+ '-Wwrite-strings',
+ '-Wno-missing-field-initializers', # SWIG 3.0.2 generates partially-initialized structs
+ '-Wno-unused-parameter', # SWIG generates functions with unused parameters
+ '-Wno-cast-qual', # libsepol/libselinux uses const-to-nonconst casts
+ '-Wno-shadow', # SWIG generates shadow variables
+ '-fno-exceptions'],
extra_link_args=['-Wl,--version-script=libqpol/libqpol.map',
'/usr/lib/libsepol.a'],
swig_opts=['-Ilibqpol/include'])]
```

Feel free to add any of these flags to ``setup.py``.

Cheers,

Nicolas