]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Replace rand_set_seed with srand
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 4 Sep 2017 12:22:13 +0000 (15:22 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Thu, 7 Sep 2017 08:40:31 +0000 (11:40 +0300)
Makes following commits easier, and also
makes sure that rand() will get seeded when
used by other libraries.

src/lib/lib.c
src/lib/rand.c
src/lib/rand.h
src/lib/randgen.c

index 4c20163d3686fa9074bafc956a54df3ec8893159..7a987ea0985b404ed520e87162267fc95c52edd9 100644 (file)
@@ -169,7 +169,7 @@ void lib_init(void)
        /* 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();
index 9c66c7cc37f6478ce22a7818987f82f0107fffcb..ec4930594ae9738aa88b1b63aba62237cf5e8e54 100644 (file)
@@ -1,37 +1,7 @@
 /* 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>
index b0de58f514bb35ace481e8408e4ed4fbfd882adc..cf3d8c2ca0ccbe0c4e27652f9a6a7a8d4198e8ab 100644 (file)
@@ -1,21 +1,6 @@
 #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);
index 0bcbe6407dd963341afc032eb54d95891a795850..332fc845975f732a314d8bddd28cbc83bcc42add 100644 (file)
@@ -48,7 +48,7 @@ void random_init(void)
        }
 
        random_fill(&seed, sizeof(seed));
-       rand_set_seed(seed);
+       srand(seed);
 
        fd_close_on_exec(urandom_fd, TRUE);
 }