/* standard way to get rand() return different values. */
if (gettimeofday(&tv, NULL) < 0)
i_fatal("gettimeofday(): %m");
- rand_set_seed((unsigned int) (tv.tv_sec ^ tv.tv_usec ^ getpid()));
+ srand((unsigned int) (tv.tv_sec ^ tv.tv_usec ^ getpid()));
data_stack_init();
hostpid_init();
/* Copyright (c) 2014-2017 Dovecot authors, see the included COPYING file */
-/* Wrap srand() so that we can reproduce fuzzed tests */
-
#include "lib.h"
-static int seeded = 0;
-static unsigned int seed;
-static char const *env_seed;
-
-int rand_get_seed_count(void)
-{
- return seeded;
-}
-unsigned int rand_get_last_seed(void)
-{
- i_assert(seeded > 0);
- return seed;
-}
-void rand_set_seed(unsigned int s)
-{
- if (seeded == 0) {
- unsigned int seedval;
- env_seed = getenv("DOVECOT_SRAND");
- if (env_seed != NULL && str_to_uint(env_seed, &seedval) >= 0)
- seed = seedval;
- }
- seeded++;
- if (env_seed == NULL)
- seed = s;
-
- srand(seed);
-}
-
#ifdef HAVE_ARC4RANDOM
#ifdef HAVE_LIBBSD
#include <bsd/stdlib.h>
#ifndef RAND_H
#define RAND_H
-/* Wrap srand() so that we can reproduce fuzzed tests */
-
-/* If we have seeded the prng precisely once, and we remember what
- * value that was with, then we can reproduce any failing test cases
- * that depend on that randomness by forcing the seed value (e.g.
- * in a debugger, by putting a breakpoint on rand_set_seed()).
- */
-
-/* Number of times we've been seeded */
-int rand_get_seed_count(void);
-/* That last seed */
-unsigned int rand_get_last_seed(void);
-/* Actually seed the prng (could add char* for name of function?) */
-void rand_set_seed(unsigned int s);
-
#ifdef HAVE_ARC4RANDOM
int arc4random_rand(void);
}
random_fill(&seed, sizeof(seed));
- rand_set_seed(seed);
+ srand(seed);
fd_close_on_exec(urandom_fd, TRUE);
}