mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-02 23:55:27 +00:00
1405. [func] Use arc4random() if available.
from: jakob@crt.se reviewed: marka
This commit is contained in:
2
CHANGES
2
CHANGES
@@ -1,3 +1,5 @@
|
||||
1405. [func] Use arc4random() if available.
|
||||
|
||||
1404. [bug] libbind: ns_name_ntol() could overwite a zero length
|
||||
buffer.
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: acconfig.h,v 1.38 2002/10/15 04:32:49 marka Exp $ */
|
||||
/* $Id: acconfig.h,v 1.39 2002/12/04 01:19:27 marka Exp $ */
|
||||
|
||||
/***
|
||||
*** This file is not to be included by any public header files, because
|
||||
@@ -76,6 +76,9 @@
|
||||
/* define if gai_strerror() exists */
|
||||
#undef HAVE_GAISTRERROR
|
||||
|
||||
/* define if arc4random() exists */
|
||||
#undef HAVE_ARC4RANDOM
|
||||
|
||||
/* define if pthread_setconcurrency() should be called to tell the
|
||||
* OS how many threads we might want to run.
|
||||
*/
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: genrandom.c,v 1.8 2001/01/09 21:41:04 bwelling Exp $ */
|
||||
/* $Id: genrandom.c,v 1.9 2002/12/04 01:19:28 marka Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -47,9 +47,15 @@ main(int argc, char **argv) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifndef HAVE_ARC4RANDOM
|
||||
srand(0x12345678);
|
||||
#endif
|
||||
while (bytes > 0) {
|
||||
#ifndef HAVE_ARC4RANDOM
|
||||
unsigned short int x = (rand() & 0xFFFF);
|
||||
#else
|
||||
unsigned short int x = (arc4random() & 0xFFFF);
|
||||
#endif
|
||||
unsigned char c = x & 0xFF;
|
||||
if (putc(c, fp) == EOF) {
|
||||
printf("error writing to file\n");
|
||||
|
@@ -18,7 +18,7 @@ AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)dnl
|
||||
esyscmd([sed "s/^/# /" COPYRIGHT])dnl
|
||||
AC_DIVERT_POP()dnl
|
||||
|
||||
AC_REVISION($Revision: 1.333 $)
|
||||
AC_REVISION($Revision: 1.334 $)
|
||||
|
||||
AC_INIT(lib/dns/name.c)
|
||||
AC_PREREQ(2.13)
|
||||
@@ -521,6 +521,11 @@ case "$use_randomdev" in
|
||||
;;
|
||||
esac
|
||||
|
||||
#
|
||||
# Do we have arc4random() ?
|
||||
#
|
||||
AC_CHECK_FUNC(arc4random, AC_DEFINE(HAVE_ARC4RANDOM))
|
||||
|
||||
#
|
||||
# Begin pthreads checking.
|
||||
#
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: rdataset.c,v 1.63 2002/04/02 06:06:29 marka Exp $ */
|
||||
/* $Id: rdataset.c,v 1.64 2002/12/04 01:19:28 marka Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -370,7 +370,11 @@ towiresorted(dns_rdataset_t *rdataset, dns_name_t *owner_name,
|
||||
*/
|
||||
for (i = 0; i < count; i++) {
|
||||
dns_rdata_t rdata;
|
||||
#ifndef HAVE_ARC4RANDOM
|
||||
choice = i + (((u_int)rand()>>3) % (count - i));
|
||||
#else
|
||||
choice = i + (((u_int)arc4random()>>3) % (count - i));
|
||||
#endif
|
||||
rdata = shuffled[i];
|
||||
shuffled[i] = shuffled[choice];
|
||||
shuffled[choice] = rdata;
|
||||
@@ -385,7 +389,11 @@ towiresorted(dns_rdataset_t *rdataset, dns_name_t *owner_name,
|
||||
/*
|
||||
* "Cyclic" order.
|
||||
*/
|
||||
#ifndef HAVE_ARC4RANDOM
|
||||
unsigned int j = (((unsigned int)rand()) >> 3) % count;
|
||||
#else
|
||||
unsigned int j = (((unsigned int)arc4random()) >> 3) % count;
|
||||
#endif
|
||||
for (i = 0; i < count; i++) {
|
||||
if (order != NULL)
|
||||
sorted[j].key = (*order)(&shuffled[i],
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: random.c,v 1.15 2001/01/09 21:56:22 bwelling Exp $ */
|
||||
/* $Id: random.c,v 1.16 2002/12/04 01:19:28 marka Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -33,7 +33,9 @@ static isc_once_t once = ISC_ONCE_INIT;
|
||||
static void
|
||||
initialize_rand(void)
|
||||
{
|
||||
#ifndef HAVE_ARC4RANDOM
|
||||
srand(time(NULL));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -47,7 +49,11 @@ isc_random_seed(isc_uint32_t seed)
|
||||
{
|
||||
initialize();
|
||||
|
||||
#ifndef HAVE_ARC4RANDOM
|
||||
srand(seed);
|
||||
#else
|
||||
arc4random_addrandom((u_char *) &seed, sizeof(isc_uint32_t));
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
@@ -57,7 +63,11 @@ isc_random_get(isc_uint32_t *val)
|
||||
|
||||
initialize();
|
||||
|
||||
#ifndef HAVE_ARC4RANDOM
|
||||
*val = rand();
|
||||
#else
|
||||
*val = arc4random();
|
||||
#endif
|
||||
}
|
||||
|
||||
isc_uint32_t
|
||||
@@ -66,5 +76,9 @@ isc_random_jitter(isc_uint32_t max, isc_uint32_t jitter) {
|
||||
if (jitter == 0)
|
||||
return (max);
|
||||
else
|
||||
#ifndef HAVE_ARC4RANDOM
|
||||
return (max - rand() % jitter);
|
||||
#else
|
||||
return (max - arc4random() % jitter);
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user