Skip to content

Commit 84a4ce9

Browse files
committed
feature: spec: asan build
As this spec is used for testing and program is complex C/C++ program, it seems prudent to use asan. Also enables ubsan. By default do not detect leaks as there was way too many to fix.
1 parent fd1cfb2 commit 84a4ce9

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ option(ENABLE_MITRE "enables MITRE tests -- requires specific environment suppor
347347
# ---------- LANGUAGE BINDINGS
348348
cmake_dependent_option(ENABLE_PYTHON3 "if enabled, the python3 swig bindings will be built" ON "PYTHONINTERP_FOUND;SWIG_FOUND;PYTHONLIBS_FOUND" OFF)
349349
cmake_dependent_option(ENABLE_PERL "if enabled, the perl swig bindings will be built" ON "PERLLIBS_FOUND;SWIG_FOUND" OFF)
350+
option(ENABLE_ASAN "if enabled, the build using asan" FALSE)
350351

351352
# ---------- NO IDEA WHAT THIS IS FOR
352353
set(WANT_BASE64 TRUE CACHE BOOL "wants builtin Base64")
@@ -535,6 +536,12 @@ if(APPLE)
535536
add_definitions(-D_DARWIN_C_SOURCE)
536537
endif()
537538

539+
if(ENABLE_ASAN)
540+
add_compile_options(-fno-common -fno-omit-frame-pointer -fsanitize=address -fsanitize-address-use-after-scope -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined)
541+
add_link_options(-fno-common -fno-omit-frame-pointer -fsanitize=address -static-libasan -fsanitize-address-use-after-scope -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined)
542+
endif()
543+
544+
538545
include_directories(
539546
"compat/"
540547
"src/"

openscap.spec

+26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# build with asan
2+
# - bindings/sce fail to work because of some asan linkage issues presumed
3+
%bcond_with asan
4+
15
# gconf is a legacy system not used any more, and it blocks testing of oscap-anaconda-addon
26
# as gconf is no longer part of the installation medium
37
%bcond_with gconf
@@ -23,6 +27,11 @@ BuildRequires: pkg-config
2327
BuildRequires: systemd-rpm-macros
2428
BuildRequires: gcc
2529
BuildRequires: gcc-c++
30+
%if %{with asan}
31+
BuildRequires: libasan
32+
BuildRequires: libasan-static
33+
BuildRequires: libubsan
34+
%endif
2635

2736
# Try to follow CMakeLists.txt order
2837
BuildRequires: pkgconfig(libacl)
@@ -126,6 +135,7 @@ The %{name}-utils package contains command-line tools build on top
126135
of OpenSCAP library. Historically, openscap-utils included oscap
127136
tool which is now separated to %{name}-scanner sub-package.
128137

138+
%if ! %{with asan}
129139
%package engine-sce
130140
Summary: Script Check Engine plug-in for OpenSCAP
131141
Requires: %{name}%{?_isa} = %{epoch}:%{version}-%{release}
@@ -143,6 +153,7 @@ Requires: %{name}-engine-sce%{?_isa} = %{epoch}:%{version}-%{release}
143153
%description engine-sce-devel
144154
The %{name}-engine-sce-devel package contains libraries and header files
145155
for developing applications that use %{name}-engine-sce.
156+
%endif
146157

147158
%package containers
148159
Summary: Utils for scanning containers
@@ -161,6 +172,12 @@ tar xvzf %{SOURCE1} --directory=yaml-filter --strip-components=1
161172
%undefine __cmake_in_source_build
162173
%cmake -G Ninja \
163174
-DENABLE_DOCS=ON \
175+
%if %{with asan}
176+
-DENABLE_ASAN=TRUE \
177+
-DENABLE_PERL=OFF \
178+
-DENABLE_PYTHON=OFF \
179+
-DENABLE_SCE=OFF \
180+
%endif
164181
%if ! %{with gconf}
165182
-DOPENSCAP_PROBE_UNIX_GCONF=OFF \
166183
-DGCONF_LIBRARY= \
@@ -176,6 +193,11 @@ make docs
176193
%if %{with check}
177194
# Tests use common files. Running tests parallel causes failed tests because of that.
178195
%undefine _smp_mflags
196+
%if %{with asan}
197+
# https://github.com/google/sanitizers/wiki/AddressSanitizer
198+
# - but do not detect leaks, program is not long running, also numerous leaks so fix these completely would require some effort
199+
export ASAN_OPTIONS=detect_leaks=0:strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1:detect_invalid_pointer_pairs=2
200+
%endif
179201
%ctest
180202
%endif
181203

@@ -218,7 +240,9 @@ ln -sf ../oscap-remediate.service %{buildroot}%{_unitdir}/system-update.target.w
218240
%{_libdir}/libopenscap.so
219241
%{_libdir}/pkgconfig/*.pc
220242
%{_includedir}/openscap
243+
%if ! %{with asan}
221244
%exclude %{_includedir}/openscap/sce_engine_api.h
245+
%endif
222246

223247
%files scanner
224248
%{_bindir}/oscap
@@ -245,13 +269,15 @@ ln -sf ../oscap-remediate.service %{buildroot}%{_unitdir}/system-update.target.w
245269
%{_mandir}/man8/oscap-vm.8*
246270
%{_mandir}/man8/scap-as-rpm.8*
247271

272+
%if ! %{with asan}
248273
%files engine-sce
249274
%{_bindir}/oscap-run-sce-script
250275
%{_libdir}/libopenscap_sce.so.*
251276

252277
%files engine-sce-devel
253278
%{_libdir}/libopenscap_sce.so
254279
%{_includedir}/openscap/sce_engine_api.h
280+
%endif
255281

256282
%files containers
257283
%{_bindir}/oscap-docker

0 commit comments

Comments
 (0)