@@ -3,6 +3,13 @@ AC_MSG_CHECKING(for clang fuzzer SAPI)
3
3
PHP_ARG_ENABLE([ fuzzer] ,,
4
4
[ AS_HELP_STRING ( [ --enable-fuzzer] ,
5
5
[ 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] ,
6
13
[ no] )
7
14
8
15
dnl For newer clang versions see https://llvm.org/docs/LibFuzzer.html#fuzzer-usage
@@ -29,16 +36,25 @@ if test "$PHP_FUZZER" != "no"; then
29
36
if test -z "$LIB_FUZZING_ENGINE"; then
30
37
FUZZING_LIB="-fsanitize=fuzzer"
31
38
FUZZING_CC="$CC"
32
- dnl Don't include -fundefined in CXXFLAGS, because that would also require linking
33
- dnl with a C++ compiler.
34
39
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
42
58
] ,[
43
59
AC_MSG_ERROR ( Compiler doesn't support - fsanitize=fuzzer-no-link )
44
60
] )
0 commit comments