From: Heiko Schlichting Date: Fri, 19 Feb 2021 11:16:10 +0000 (+0000) Subject: Use random_number rather than random, for external server distribution. Bug 2694 X-Git-Url: https://git.exim.org/users/heiko/exim.git/commitdiff_plain/213da388e7834c078ed5fd2e0063c951db0d8080?hp=83811e3c1b8189c0a725ec53df699730e7767263 Use random_number rather than random, for external server distribution. Bug 2694 --- diff --git a/src/src/spam.c b/src/src/spam.c index b0e24b368..286038678 100644 --- a/src/src/spam.c +++ b/src/src/spam.c @@ -139,21 +139,11 @@ unsigned int i; spamd_address_container * sd; long weights; unsigned pri; -static BOOL srandomed = FALSE; /* speedup, if we have only 1 server */ if (num_servers == 1) return (spamds[0]->is_failed ? -1 : 0); -/* init ranmod */ -if (!srandomed) - { - struct timeval tv; - gettimeofday(&tv, NULL); - srandom((unsigned int)(tv.tv_usec/1000)); - srandomed = TRUE; - } - /* scan for highest pri */ for (pri = 0, i = 0; i < num_servers; i++) { @@ -170,7 +160,7 @@ for (weights = 0, i = 0; i < num_servers; i++) if (weights == 0) /* all servers failed */ return -1; -for (long rnd = random() % weights, i = 0; i < num_servers; i++) +for (long rnd = random_number(weights), i = 0; i < num_servers; i++) { sd = spamds[i]; if (!sd->is_failed && sd->priority == pri) diff --git a/src/src/transports/smtp_socks.c b/src/src/transports/smtp_socks.c index cd8ed3e6d..22cfbecb4 100644 --- a/src/src/transports/smtp_socks.c +++ b/src/src/transports/smtp_socks.c @@ -160,20 +160,10 @@ socks_opts * sd; socks_opts * lim = &proxies[nproxies]; long rnd, weights; unsigned pri; -static BOOL srandomed = FALSE; if (nproxies == 1) /* shortcut, if we have only 1 server */ return (proxies[0].is_failed ? -1 : 0); -/* init random */ -if (!srandomed) - { - struct timeval tv; - gettimeofday(&tv, NULL); - srandom((unsigned int)(tv.tv_usec/1000)); - srandomed = TRUE; - } - /* scan for highest pri */ for (pri = 0, sd = proxies; sd < lim; sd++) if (!sd->is_failed && sd->priority > pri) @@ -186,7 +176,7 @@ for (weights = 0, sd = proxies; sd < lim; sd++) if (weights == 0) /* all servers failed */ return -1; -for (rnd = random() % weights, i = 0; i < nproxies; i++) +for (rnd = random_number(weights), i = 0; i < nproxies; i++) { sd = &proxies[i]; if (!sd->is_failed && sd->priority == pri)