mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-04 00:25:29 +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
|
1404. [bug] libbind: ns_name_ntol() could overwite a zero length
|
||||||
buffer.
|
buffer.
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* 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
|
*** This file is not to be included by any public header files, because
|
||||||
@@ -76,6 +76,9 @@
|
|||||||
/* define if gai_strerror() exists */
|
/* define if gai_strerror() exists */
|
||||||
#undef HAVE_GAISTRERROR
|
#undef HAVE_GAISTRERROR
|
||||||
|
|
||||||
|
/* define if arc4random() exists */
|
||||||
|
#undef HAVE_ARC4RANDOM
|
||||||
|
|
||||||
/* define if pthread_setconcurrency() should be called to tell the
|
/* define if pthread_setconcurrency() should be called to tell the
|
||||||
* OS how many threads we might want to run.
|
* OS how many threads we might want to run.
|
||||||
*/
|
*/
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* 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>
|
#include <config.h>
|
||||||
|
|
||||||
@@ -47,9 +47,15 @@ main(int argc, char **argv) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_ARC4RANDOM
|
||||||
srand(0x12345678);
|
srand(0x12345678);
|
||||||
|
#endif
|
||||||
while (bytes > 0) {
|
while (bytes > 0) {
|
||||||
|
#ifndef HAVE_ARC4RANDOM
|
||||||
unsigned short int x = (rand() & 0xFFFF);
|
unsigned short int x = (rand() & 0xFFFF);
|
||||||
|
#else
|
||||||
|
unsigned short int x = (arc4random() & 0xFFFF);
|
||||||
|
#endif
|
||||||
unsigned char c = x & 0xFF;
|
unsigned char c = x & 0xFF;
|
||||||
if (putc(c, fp) == EOF) {
|
if (putc(c, fp) == EOF) {
|
||||||
printf("error writing to file\n");
|
printf("error writing to file\n");
|
||||||
|
@@ -18,7 +18,7 @@ AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)dnl
|
|||||||
esyscmd([sed "s/^/# /" COPYRIGHT])dnl
|
esyscmd([sed "s/^/# /" COPYRIGHT])dnl
|
||||||
AC_DIVERT_POP()dnl
|
AC_DIVERT_POP()dnl
|
||||||
|
|
||||||
AC_REVISION($Revision: 1.333 $)
|
AC_REVISION($Revision: 1.334 $)
|
||||||
|
|
||||||
AC_INIT(lib/dns/name.c)
|
AC_INIT(lib/dns/name.c)
|
||||||
AC_PREREQ(2.13)
|
AC_PREREQ(2.13)
|
||||||
@@ -521,6 +521,11 @@ case "$use_randomdev" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
#
|
||||||
|
# Do we have arc4random() ?
|
||||||
|
#
|
||||||
|
AC_CHECK_FUNC(arc4random, AC_DEFINE(HAVE_ARC4RANDOM))
|
||||||
|
|
||||||
#
|
#
|
||||||
# Begin pthreads checking.
|
# Begin pthreads checking.
|
||||||
#
|
#
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* 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>
|
#include <config.h>
|
||||||
|
|
||||||
@@ -370,7 +370,11 @@ 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
|
||||||
choice = i + (((u_int)rand()>>3) % (count - i));
|
choice = i + (((u_int)rand()>>3) % (count - i));
|
||||||
|
#else
|
||||||
|
choice = i + (((u_int)arc4random()>>3) % (count - i));
|
||||||
|
#endif
|
||||||
rdata = shuffled[i];
|
rdata = shuffled[i];
|
||||||
shuffled[i] = shuffled[choice];
|
shuffled[i] = shuffled[choice];
|
||||||
shuffled[choice] = rdata;
|
shuffled[choice] = rdata;
|
||||||
@@ -385,7 +389,11 @@ towiresorted(dns_rdataset_t *rdataset, dns_name_t *owner_name,
|
|||||||
/*
|
/*
|
||||||
* "Cyclic" order.
|
* "Cyclic" order.
|
||||||
*/
|
*/
|
||||||
|
#ifndef HAVE_ARC4RANDOM
|
||||||
unsigned int j = (((unsigned int)rand()) >> 3) % count;
|
unsigned int j = (((unsigned int)rand()) >> 3) % count;
|
||||||
|
#else
|
||||||
|
unsigned int j = (((unsigned int)arc4random()) >> 3) % 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.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>
|
#include <config.h>
|
||||||
|
|
||||||
@@ -33,7 +33,9 @@ static isc_once_t once = ISC_ONCE_INIT;
|
|||||||
static void
|
static void
|
||||||
initialize_rand(void)
|
initialize_rand(void)
|
||||||
{
|
{
|
||||||
|
#ifndef HAVE_ARC4RANDOM
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -47,7 +49,11 @@ isc_random_seed(isc_uint32_t seed)
|
|||||||
{
|
{
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
|
#ifndef HAVE_ARC4RANDOM
|
||||||
srand(seed);
|
srand(seed);
|
||||||
|
#else
|
||||||
|
arc4random_addrandom((u_char *) &seed, sizeof(isc_uint32_t));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -57,7 +63,11 @@ isc_random_get(isc_uint32_t *val)
|
|||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
|
#ifndef HAVE_ARC4RANDOM
|
||||||
*val = rand();
|
*val = rand();
|
||||||
|
#else
|
||||||
|
*val = arc4random();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_uint32_t
|
isc_uint32_t
|
||||||
@@ -66,5 +76,9 @@ isc_random_jitter(isc_uint32_t max, isc_uint32_t jitter) {
|
|||||||
if (jitter == 0)
|
if (jitter == 0)
|
||||||
return (max);
|
return (max);
|
||||||
else
|
else
|
||||||
|
#ifndef HAVE_ARC4RANDOM
|
||||||
return (max - rand() % jitter);
|
return (max - rand() % jitter);
|
||||||
|
#else
|
||||||
|
return (max - arc4random() % jitter);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user