Skip to content

Commit dfa95be

Browse files
committed
Fix ASAN usage
Previously if ASAN libraries were detected, it would enable the use of ASAN in the auparse unit tests. This means it can be enabled by accident when people didn't want it at all. Now require --with-asan to enable ASAN for unit tests only. And support ASAN in all unit tests.
1 parent 7997d76 commit dfa95be

File tree

7 files changed

+53
-10
lines changed

7 files changed

+53
-10
lines changed

audisp/plugins/remote/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ noinst_HEADERS = remote-config.h queue.h
3434
man_MANS = audisp-remote.8 audisp-remote.conf.5
3535
check_PROGRAMS = test-queue
3636
TESTS = $(check_PROGRAMS)
37+
if HAVE_ASAN
38+
test_queue_CFLAGS = ${ASAN_FLAGS}
39+
test_queue_LDFLAGS = ${ASAN_FLAGS}
40+
endif
3741

3842
audisp_remote_DEPENDENCIES = ${top_builddir}/lib/libaudit.la ${top_builddir}/common/libaucommon.la ${top_builddir}/auplugin/libauplugin.la
3943
audisp_remote_SOURCES = audisp-remote.c remote-config.c queue.c

audisp/test/Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
AM_CPPFLAGS = -D_GNU_SOURCE -I${top_srcdir} -I${top_srcdir}/audisp \
2424
-I${top_srcdir}/common -I${top_srcdir}/src -I${top_srcdir}/lib
2525
AM_CFLAGS = -D_GNU_SOURCE -Wno-pointer-sign ${WFLAGS}
26+
AM_LDFLAGS =
27+
if HAVE_ASAN
28+
AM_CFLAGS += ${ASAN_FLAGS}
29+
AM_LDFLAGS += ${ASAN_FLAGS}
30+
endif
2631
check_PROGRAMS = audisp-queue-test audisp-llist-test
2732
TESTS = $(check_PROGRAMS)
2833

auplugin/test/Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222

2323
AM_CPPFLAGS = -I${top_srcdir}/auplugin -I${top_srcdir}/lib -I${top_srcdir}/auparse
2424
AM_CFLAGS = -D_GNU_SOURCE -Wno-pointer-sign ${WFLAGS}
25+
AM_LDFLAGS =
26+
if HAVE_ASAN
27+
AM_CFLAGS += ${ASAN_FLAGS}
28+
AM_LDFLAGS += ${ASAN_FLAGS}
29+
endif
2530
check_PROGRAMS = fgets_test metrics_test fgets_r_test
2631
TESTS = $(check_PROGRAMS)
2732

configure.ac

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,30 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[WFLAGS="${WFLAGS} -Wno-unused-but-
301301
CFLAGS="${TMPCFLAGS}"
302302
AC_SUBST(WFLAGS)
303303

304-
AC_MSG_CHECKING([for -fsanitize=address])
305-
TMPCFLAGS="${CFLAGS}"
306-
TMPLDFLAGS="${LDFLAGS}"
307-
CFLAGS="${CFLAGS} -fsanitize=address"
308-
LDFLAGS="${LDFLAGS} -fsanitize=address"
309-
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
310-
[ASAN_FLAGS="-fsanitize=address"; have_asan=yes; AC_MSG_RESULT(yes)],
311-
[have_asan=no; AC_MSG_RESULT(no)])
312-
CFLAGS="${TMPCFLAGS}"
313-
LDFLAGS="${TMPLDFLAGS}"
304+
AC_ARG_WITH([asan],
305+
[AS_HELP_STRING([--with-asan],
306+
[build unit tests with AddressSanitizer instrumentation])],
307+
[case "${withval}" in
308+
yes) want_asan="yes" ;;
309+
no) want_asan="no" ;;
310+
*) AC_MSG_ERROR(bad value ${withval} for --with-asan) ;;
311+
esac],
312+
[want_asan="no"])
313+
314+
have_asan=no
315+
ASAN_FLAGS=""
316+
if test x$want_asan = xyes; then
317+
AC_MSG_CHECKING([for -fsanitize=address support])
318+
TMPCFLAGS="${CFLAGS}"
319+
TMPLDFLAGS="${LDFLAGS}"
320+
CFLAGS="${CFLAGS} -fsanitize=address"
321+
LDFLAGS="${LDFLAGS} -fsanitize=address"
322+
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
323+
[ASAN_FLAGS="-fsanitize=address"; have_asan=yes; AC_MSG_RESULT(yes)],
324+
[AC_MSG_FAILURE([--with-asan was given, but -fsanitize=address is not supported by the compiler or linker])])
325+
CFLAGS="${TMPCFLAGS}"
326+
LDFLAGS="${TMPLDFLAGS}"
327+
fi
314328
AC_SUBST(ASAN_FLAGS)
315329
AM_CONDITIONAL(HAVE_ASAN, test x$have_asan = xyes)
316330
AM_CONDITIONAL(BUILD_STATIC, test "x$enable_static" != "xno")

lib/test/Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121

2222
AM_CPPFLAGS = -I${top_srcdir}/lib
2323
AM_CFLAGS = -D_GNU_SOURCE -Wno-pointer-sign ${WFLAGS}
24+
AM_LDFLAGS =
25+
if HAVE_ASAN
26+
AM_CFLAGS += ${ASAN_FLAGS}
27+
AM_LDFLAGS += ${ASAN_FLAGS}
28+
endif
2429
check_PROGRAMS = lookup_test
2530
TESTS = $(check_PROGRAMS)
2631

src/test/Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121

2222
AM_CPPFLAGS = -I${top_srcdir} -I${top_srcdir}/lib -I${top_srcdir}/src
2323
AM_CFLAGS = -D_GNU_SOURCE -Wno-pointer-sign ${WFLAGS}
24+
AM_LDFLAGS =
25+
if HAVE_ASAN
26+
AM_CFLAGS += ${ASAN_FLAGS}
27+
AM_LDFLAGS += ${ASAN_FLAGS}
28+
endif
2429
check_PROGRAMS = ilist_test slist_test format_event_test
2530
TESTS = $(check_PROGRAMS)
2631
ilist_test_LDADD = ${top_builddir}/src/ausearch-int.o

tools/aulast/test/Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@ TESTS = aulast_llist_test
55
AM_CPPFLAGS = -I${top_srcdir}/tools/aulast
66

77
aulast_llist_test_SOURCES = aulast_llist_test.c ${top_srcdir}/tools/aulast/aulast-llist.c
8+
if HAVE_ASAN
9+
aulast_llist_test_CFLAGS = ${ASAN_FLAGS}
10+
aulast_llist_test_LDFLAGS = ${ASAN_FLAGS}
11+
else
812
aulast_llist_test_LDFLAGS = -static
13+
endif

0 commit comments

Comments
 (0)