From ee7502accde339a77911e2872292b4d0da18c457 Mon Sep 17 00:00:00 2001 From: Sergio Gelato Date: Sun, 6 Dec 2015 12:57:46 +0100 Subject: [PATCH] ITS#8204 Remove bias towards the first record in RFC2782 shuffle implementation. Prior to this change, given two records of weight 1 the algorithm would return them in the order (0,1) with 100% probability instead of the desired 50%. This was due to an off-by-one error in the range test. srv_rand() returns a float in the range [0.0, 1.0[, so r is an integer in the range [0, total[. The correct probability for record 0 to be chosen is a[0].weight/total, not (a[0].weight+1)/total. --- libraries/libldap/dnssrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/libldap/dnssrv.c b/libraries/libldap/dnssrv.c index 10f179dc2e..1503c068b6 100644 --- a/libraries/libldap/dnssrv.c +++ b/libraries/libldap/dnssrv.c @@ -234,7 +234,7 @@ static void srv_shuffle(srv_record *a, int n) { r = srv_rand() * total; for (j=0; j