Fix bias in ordering SRV RR results by weight.
commit44a1a2a273d498ac8d9334930150b4480a2fbe5c
authorRoland C. Dowdeswell <elric@imrryr.org>
Wed, 9 Mar 2016 15:51:02 +0000 (9 10:51 -0500)
committerViktor Dukhovni <viktor1ghub@dukhovni.org>
Thu, 10 Nov 2016 09:45:07 +0000 (10 04:45 -0500)
tree06d1b9d0af5a3c5ff0b193f92b6668f72c51ab3f
parent13cb3b5646e19b930d411ecb6a8376250930225b
Fix bias in ordering SRV RR results by weight.

In lib/roken/resolve.c, we find rk_dns_srv_order() which re-orders
the results of an SRV RR lookup by the algorithm in RFC2782.  We
fix a bias in the random weight sorting by changing the order of
operations when selecting rnd.  rnd should be a non-zero random
number less than the sum of the weights at a particular priority,
but zero was included as a legitimate output thus biasing the
selection process.  rk_random() % sum is still biased as a 32
bit int modulo a number which doesn't divide 2^32 does not have
a uniform distribution, but the bias should be small enough to
live with for our purposes here.
lib/roken/resolve.c