Skip to content

Commit 4d49ec2

Browse files
committed
Add --enable-fuzzer-msan flag
To build fuzzers with memory sanitizer.
1 parent b53d952 commit 4d49ec2

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

sapi/fuzzer/config.m4

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ AC_MSG_CHECKING(for clang fuzzer SAPI)
33
PHP_ARG_ENABLE([fuzzer],,
44
[AS_HELP_STRING([--enable-fuzzer],
55
[Build PHP as clang fuzzing test module (for developers)])],
6+
[no],
7+
[no])
8+
9+
PHP_ARG_ENABLE([fuzzer-msan],,
10+
[AS_HELP_STRING([--enable-fuzzer-msan],
11+
[Enable msan instead of asan/ubsan when fuzzing])],
12+
[no],
613
[no])
714

815
dnl For newer clang versions see https://llvm.org/docs/LibFuzzer.html#fuzzer-usage
@@ -29,16 +36,25 @@ if test "$PHP_FUZZER" != "no"; then
2936
if test -z "$LIB_FUZZING_ENGINE"; then
3037
FUZZING_LIB="-fsanitize=fuzzer"
3138
FUZZING_CC="$CC"
32-
dnl Don't include -fundefined in CXXFLAGS, because that would also require linking
33-
dnl with a C++ compiler.
3439
AX_CHECK_COMPILE_FLAG([-fsanitize=fuzzer-no-link], [
35-
CFLAGS="$CFLAGS -fsanitize=fuzzer-no-link,address"
36-
dnl Disable object-size sanitizer, because it is incompatible with our zend_function
37-
dnl union, and this can't be easily fixed.
38-
dnl We need to specify -fno-sanitize-recover=undefined here, otherwise ubsan warnings
39-
dnl will not be considered failures by the fuzzer.
40-
CFLAGS="$CFLAGS -fsanitize=undefined -fno-sanitize=object-size -fno-sanitize-recover=undefined"
41-
CXXFLAGS="$CXXFLAGS -fsanitize=fuzzer-no-link,address"
40+
CFLAGS="$CFLAGS -fsanitize=fuzzer-no-link"
41+
CXXFLAGS="$CXXFLAGS -fsanitize=fuzzer-no-link"
42+
43+
if test "$PHP_FUZZER_MSAN" = "yes"; then
44+
CFLAGS="$CFLAGS -fsanitize=memory -fsanitize-memory-track-origins"
45+
CXXFLAGS="$CXXFLAGS -fsanitize=memory -fsanitize-memory-track-origins"
46+
else
47+
CFLAGS="$CFLAGS -fsanitize=address"
48+
CXXFLAGS="$CXXFLAGS -fsanitize=address"
49+
50+
dnl Don't include -fundefined in CXXFLAGS, because that would also require linking
51+
dnl with a C++ compiler.
52+
dnl Disable object-size sanitizer, because it is incompatible with our zend_function
53+
dnl union, and this can't be easily fixed.
54+
dnl We need to specify -fno-sanitize-recover=undefined here, otherwise ubsan warnings
55+
dnl will not be considered failures by the fuzzer.
56+
CFLAGS="$CFLAGS -fsanitize=undefined -fno-sanitize=object-size -fno-sanitize-recover=undefined"
57+
fi
4258
],[
4359
AC_MSG_ERROR(Compiler doesn't support -fsanitize=fuzzer-no-link)
4460
])

0 commit comments

Comments
 (0)