with_fuzzer=no)
AS_IF([test x$with_fuzzer = xclang], [
AM_CFLAGS="$AM_CFLAGS -fsanitize=fuzzer-no-link"
+ AM_CFLAGS="$AM_CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION"
# use $LIB_FUZZING_ENGINE for linking if it exists
FUZZER_LDFLAGS=${LIB_FUZZING_ENGINE--fsanitize=fuzzer}
# May need to use CXXLINK for linking, which wants sources to
#include <unistd.h>
#include <fcntl.h>
-#ifdef DEBUG
+#if defined(DEBUG) || defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
/* For reproducing tests, fall back onto using a simple deterministic PRNG */
/* Marsaglia's 1999 KISS, de-macro-ified, and with the fixed KISS11 SHR3,
which is clearly what was intended given the "cycle length 2^123" claim. */
i_assert(init_refcount > 0);
i_assert(size < SSIZE_T_MAX);
-#ifdef DEBUG
+#if defined(DEBUG) || defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
if (kiss_in_use) {
for (size_t pos = 0; pos < size; pos++)
((unsigned char*)buf)[pos] = kiss_rand();
void random_init(void)
{
+ if (init_refcount++ > 0)
+ return;
+
+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ kiss_init(0);
+ srand(0);
+#else
/* static analyzer seems to require this */
unsigned int seed = 0;
const char *env_seed;
- if (init_refcount++ > 0)
- return;
-
env_seed = getenv("DOVECOT_SRAND");
#ifdef DEBUG
if (env_seed != NULL && str_to_uint(env_seed, &seed) >= 0) {
normal_exit:
#endif
srand(seed);
+#endif
}
void random_deinit(void)
void random_init(void);
void random_deinit(void);
-#ifdef DEBUG
+#if defined(DEBUG) || defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
/* Debug helper to make random tests reproduceable. 0=got seed, -1=failure. */
int rand_get_last_seed(unsigned int *seed_r);
#endif