Skip to content

Commit

Permalink
conditionally enable differential fuzzing (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
addisoncrump authored Feb 16, 2024
1 parent 488af9e commit 30a3acd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
21 changes: 21 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ AC_ARG_ENABLE(fuzz_support,
[enable fuzzer support]),
, enable_fuzz_support=no)

# Handle --enable-diff-fuzz-support
AC_ARG_ENABLE(diff_fuzz_support,
AS_HELP_STRING([--enable-diff-fuzz-support],
[enable differential fuzzer support]),
, enable_diff_fuzz_support=no)

# Handle --disable-stack-for-recursion
# This option became obsolete at release 10.30.
AC_ARG_ENABLE(stack-for-recursion,,
Expand Down Expand Up @@ -529,12 +535,26 @@ AM_CONDITIONAL(WITH_JIT, test "x$enable_jit" = "xyes")
AM_CONDITIONAL(WITH_UNICODE, test "x$enable_unicode" = "xyes")
AM_CONDITIONAL(WITH_VALGRIND, test "x$enable_valgrind" = "xyes")
AM_CONDITIONAL(WITH_FUZZ_SUPPORT, test "x$enable_fuzz_support" = "xyes")
AM_CONDITIONAL(WITH_DIFF_FUZZ_SUPPORT, test "x$enable_diff_fuzz_support" = "xyes")

if test "$enable_fuzz_support" = "yes" -a "$enable_pcre2_8" = "no"; then
echo "** ERROR: Fuzzer support requires the 8-bit library"
exit 1
fi

if test "$enable_diff_fuzz_support" = "yes"; then
if test "$enable_fuzz_support" = "no"; then
echo "** ERROR: Differential fuzzing support requires fuzzing support"
exit 1
fi
if test "$enable_jit" = "no"; then
echo "** ERROR: Differential fuzzing support requires Just-in-Time compilation support"
exit 1
fi
AC_DEFINE([SUPPORT_DIFF_FUZZ], [], [
Define to any value to enable differential fuzzing support.])
fi

# Checks for typedefs, structures, and compiler characteristics.

AC_C_CONST
Expand Down Expand Up @@ -1162,6 +1182,7 @@ $PACKAGE-$VERSION configuration summary:
Valgrind support ................... : ${enable_valgrind}
Code coverage ...................... : ${enable_coverage}
Fuzzer support ..................... : ${enable_fuzz_support}
Differential fuzzer support ........ : ${enable_diff_fuzz_support}
Use %zu and %td .................... : ${enable_percent_zt}

EOF
Expand Down
37 changes: 15 additions & 22 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ sure both macros are undefined; an emulation function will then be used. */
/* Define this if your compiler supports __attribute__((uninitialized)) */
#undef HAVE_ATTRIBUTE_UNINITIALIZED

/* Define to 1 if you have the 'bcopy' function. */
/* Define to 1 if you have the `bcopy' function. */
#undef HAVE_BCOPY

/* Define this if your compiler provides __builtin_mul_overflow() */
Expand All @@ -82,16 +82,16 @@ sure both macros are undefined; an emulation function will then be used. */
/* Define to 1 if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H

/* Define to 1 if you have the 'memfd_create' function. */
/* Define to 1 if you have the `memfd_create' function. */
#undef HAVE_MEMFD_CREATE

/* Define to 1 if you have the 'memmove' function. */
/* Define to 1 if you have the `memmove' function. */
#undef HAVE_MEMMOVE

/* Define to 1 if you have the <minix/config.h> header file. */
#undef HAVE_MINIX_CONFIG_H

/* Define to 1 if you have the 'mkostemp' function. */
/* Define to 1 if you have the `mkostemp' function. */
#undef HAVE_MKOSTEMP

/* Define if you have POSIX threads libraries and header files. */
Expand All @@ -112,7 +112,7 @@ sure both macros are undefined; an emulation function will then be used. */
/* Define to 1 if you have the `realpath' function. */
#undef HAVE_REALPATH

/* Define to 1 if you have the 'secure_getenv' function. */
/* Define to 1 if you have the `secure_getenv' function. */
#undef HAVE_SECURE_GETENV

/* Define to 1 if you have the <stdint.h> header file. */
Expand All @@ -124,7 +124,7 @@ sure both macros are undefined; an emulation function will then be used. */
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H

/* Define to 1 if you have the 'strerror' function. */
/* Define to 1 if you have the `strerror' function. */
#undef HAVE_STRERROR

/* Define to 1 if you have the <strings.h> header file. */
Expand Down Expand Up @@ -287,11 +287,14 @@ sure both macros are undefined; an emulation function will then be used. */
unless SUPPORT_JIT is also defined. */
#undef SLJIT_PROT_EXECUTABLE_ALLOCATOR

/* Define to 1 if all of the C89 standard headers exist (not just the ones
/* Define to 1 if all of the C90 standard headers exist (not just the ones
required in a freestanding environment). This macro is provided for
backward compatibility; new code need not use it. */
#undef STDC_HEADERS

/* Define to any value to enable differential fuzzing support. */
#undef SUPPORT_DIFF_FUZZ

/* Define to any value to enable support for Just-In-Time compiling. */
#undef SUPPORT_JIT

Expand Down Expand Up @@ -339,7 +342,7 @@ sure both macros are undefined; an emulation function will then be used. */
/* Define to any value for valgrind support to find invalid memory reads. */
#undef SUPPORT_VALGRIND

/* Enable extensions on AIX, Interix, z/OS. */
/* Enable extensions on AIX 3, Interix. */
#ifndef _ALL_SOURCE
# undef _ALL_SOURCE
#endif
Expand Down Expand Up @@ -400,15 +403,11 @@ sure both macros are undefined; an emulation function will then be used. */
#ifndef __STDC_WANT_IEC_60559_DFP_EXT__
# undef __STDC_WANT_IEC_60559_DFP_EXT__
#endif
/* Enable extensions specified by C23 Annex F. */
#ifndef __STDC_WANT_IEC_60559_EXT__
# undef __STDC_WANT_IEC_60559_EXT__
#endif
/* Enable extensions specified by ISO/IEC TS 18661-4:2015. */
#ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__
# undef __STDC_WANT_IEC_60559_FUNCS_EXT__
#endif
/* Enable extensions specified by C23 Annex H and ISO/IEC TS 18661-3:2015. */
/* Enable extensions specified by ISO/IEC TS 18661-3:2015. */
#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
# undef __STDC_WANT_IEC_60559_TYPES_EXT__
#endif
Expand Down Expand Up @@ -437,21 +436,15 @@ sure both macros are undefined; an emulation function will then be used. */
/* Number of bits in a file offset, on hosts where this is settable. */
#undef _FILE_OFFSET_BITS

/* Define to 1 on platforms where this makes off_t a 64-bit type. */
/* Define for large files, on AIX-style hosts. */
#undef _LARGE_FILES

/* Number of bits in time_t, on hosts where this is settable. */
#undef _TIME_BITS

/* Define to 1 on platforms where this makes time_t a 64-bit type. */
#undef __MINGW_USE_VC2005_COMPAT

/* Define to empty if 'const' does not conform to ANSI C. */
/* Define to empty if `const' does not conform to ANSI C. */
#undef const

/* Define to the type of a signed integer type of width exactly 64 bits if
such a type exists and the standard includes do not define it. */
#undef int64_t

/* Define as 'unsigned int' if <stddef.h> doesn't define. */
/* Define to `unsigned int' if <sys/types.h> does not define. */
#undef size_t
4 changes: 4 additions & 0 deletions src/pcre2_fuzzsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ for (int index = 0; index < count; index++)
/* This function describes the current test case being evaluated, then aborts */

#ifdef SUPPORT_JIT
#ifdef SUPPORT_DIFF_FUZZ
static void describe_failure(
const char *task,
const unsigned char *data,
Expand Down Expand Up @@ -204,6 +205,7 @@ if (matches_jit >= 0)
abort();
}
#endif
#endif

/* This is the callout function. Its only purpose is to halt matching if there
are more than 100 callouts, as one way of stopping too much time being spent on
Expand Down Expand Up @@ -393,6 +395,7 @@ for (i = 0; i < 2; i++)
errorcode_jit = pcre2_match(code, (PCRE2_SPTR)data, (PCRE2_SIZE)match_size, 0,
match_options & ~PCRE2_NO_JIT, match_data_jit, match_context);

#ifdef SUPPORT_DIFF_FUZZ
matches = errorcode;
matches_jit = errorcode_jit;

Expand Down Expand Up @@ -446,6 +449,7 @@ for (i = 0; i < 2; i++)
pcre2_substring_free(bufferptr_jit);
}
}
#endif
}
#endif

Expand Down

0 comments on commit 30a3acd

Please sign in to comment.