mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 15:05:23 +00:00
use isc_random_get() rather than rand()/arc4random() directly.
developer: marka reviewer: bwelling
This commit is contained in:
@@ -15,13 +15,14 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: rdataset.c,v 1.65 2002/12/04 04:54:28 marka Exp $ */
|
/* $Id: rdataset.c,v 1.66 2002/12/05 04:36:26 marka Exp $ */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <isc/buffer.h>
|
#include <isc/buffer.h>
|
||||||
|
#include <isc/random.h>
|
||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
|
|
||||||
#include <dns/name.h>
|
#include <dns/name.h>
|
||||||
@@ -370,12 +371,10 @@ towiresorted(dns_rdataset_t *rdataset, dns_name_t *owner_name,
|
|||||||
*/
|
*/
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
dns_rdata_t rdata;
|
dns_rdata_t rdata;
|
||||||
#ifndef HAVE_ARC4RANDOM
|
isc_uint32_t val;
|
||||||
/* rand()'s lower bits are not random. */
|
|
||||||
choice = i + (((u_int)rand()>>3) % (count - i));
|
isc_random_get(&val);
|
||||||
#else
|
choice = i + (val % (count - i));
|
||||||
choice = i + (u_int)arc4random() % (count - i);
|
|
||||||
#endif
|
|
||||||
rdata = shuffled[i];
|
rdata = shuffled[i];
|
||||||
shuffled[i] = shuffled[choice];
|
shuffled[i] = shuffled[choice];
|
||||||
shuffled[choice] = rdata;
|
shuffled[choice] = rdata;
|
||||||
@@ -390,12 +389,11 @@ towiresorted(dns_rdataset_t *rdataset, dns_name_t *owner_name,
|
|||||||
/*
|
/*
|
||||||
* "Cyclic" order.
|
* "Cyclic" order.
|
||||||
*/
|
*/
|
||||||
#ifndef HAVE_ARC4RANDOM
|
isc_uint32_t val;
|
||||||
/* rand()'s lower bits are not random. */
|
unsigned int j;
|
||||||
unsigned int j = (((unsigned int)rand()) >> 3) % count;
|
|
||||||
#else
|
isc_random_get(&val);
|
||||||
unsigned int j = (unsigned int)arc4random() % count;
|
j = val % count;
|
||||||
#endif
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
if (order != NULL)
|
if (order != NULL)
|
||||||
sorted[j].key = (*order)(&shuffled[i],
|
sorted[j].key = (*order)(&shuffled[i],
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: random.c,v 1.16 2002/12/04 01:19:28 marka Exp $ */
|
/* $Id: random.c,v 1.17 2002/12/05 04:36:26 marka Exp $ */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
@@ -64,7 +64,11 @@ isc_random_get(isc_uint32_t *val)
|
|||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
#ifndef HAVE_ARC4RANDOM
|
#ifndef HAVE_ARC4RANDOM
|
||||||
*val = rand();
|
/*
|
||||||
|
* rand()'s lower bits are not random.
|
||||||
|
* rand()'s upper bit is zero.
|
||||||
|
*/
|
||||||
|
*val = ((rand() >> 4) & 0xffff) | ((rand() << 12) & 0xffff0000) ;
|
||||||
#else
|
#else
|
||||||
*val = arc4random();
|
*val = arc4random();
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user