Gitweb:
https://git.exim.org/exim.git/commitdiff/213da388e7834c078ed5fd2e0063c951db0d8080
Commit: 213da388e7834c078ed5fd2e0063c951db0d8080
Parent: 83811e3c1b8189c0a725ec53df699730e7767263
Author: Heiko Schlichting <heiko@???>
AuthorDate: Fri Feb 19 11:16:10 2021 +0000
Committer: Jeremy Harris <jgh146exb@???>
CommitDate: Fri Feb 19 11:55:56 2021 +0000
Use random_number rather than random, for external server distribution. Bug 2694
---
src/src/spam.c | 12 +-----------
src/src/transports/smtp_socks.c | 12 +-----------
2 files changed, 2 insertions(+), 22 deletions(-)
diff --git a/src/src/spam.c b/src/src/spam.c
index b0e24b3..2860386 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 cd8ed3e..22cfbec 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)