From: Nick Mathewson Date: Sun, 15 Nov 2009 18:59:48 +0000 (+0000) Subject: Use arc4random() for dns transaction ids where available. Patch taken from OpenBSD X-Git-Tag: release-2.0.3-alpha~21 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e2b2de79bfb3e50bfcb943b145ac45e7f68c9616;p=libevent Use arc4random() for dns transaction ids where available. Patch taken from OpenBSD svn:r1528 --- diff --git a/ChangeLog b/ChangeLog index 4834f424..d369e524 100644 --- a/ChangeLog +++ b/ChangeLog @@ -44,6 +44,7 @@ Changes in 2.0.3-alpha: o Make EV_PERSIST timeouts more accurate: schedule the next event based on the scheduled time of the previous event, not based on the current time. o Allow http.c to handle cases where getaddrinfo returns an IPv6 address. Patch from Ryan Phillips. o Fix a problem with excessive memory allocation when using multiple event priorities. + o Default to using arc4random for DNS transaction IDs on systems that have it. Changes in 2.0.2-alpha: diff --git a/configure.in b/configure.in index 2056d411..9e45bbf8 100644 --- a/configure.in +++ b/configure.in @@ -176,14 +176,16 @@ AC_C_INLINE AC_HEADER_TIME dnl Checks for library functions. -AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep getaddrinfo getnameinfo strlcpy inet_ntop inet_pton signal sigaction strtoll inet_aton pipe eventfd sendfile mmap splice) +AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep getaddrinfo getnameinfo strlcpy inet_ntop inet_pton signal sigaction strtoll inet_aton pipe eventfd sendfile mmap splice arc4random) AC_CHECK_SIZEOF(long) -if test "x$ac_cv_func_clock_gettime" = "xyes"; then - AC_DEFINE(DNS_USE_CPU_CLOCK_FOR_ID, 1, [Define if clock_gettime is available in libc]) +if test "x$ac_cv_func_arc4random" = "xyes" ; then + AC_DEFINE(DNS_USE_ARC4RANDOM_FOR_ID, 1, [Define if we should use arc4random to generate dns transation IDs]) +elif test "x$ac_cv_func_clock_gettime" = "xyes"; then + AC_DEFINE(DNS_USE_CPU_CLOCK_FOR_ID, 1, [Define if we should use clock_gettime to generate dns transation IDs]) else - AC_DEFINE(DNS_USE_GETTIMEOFDAY_FOR_ID, 1, [Define is no secure id variant is available]) + AC_DEFINE(DNS_USE_GETTIMEOFDAY_FOR_ID, 1, [Define if s no secure id variant is available]) fi AC_MSG_CHECKING(for F_SETFD in fcntl.h) diff --git a/evdns.c b/evdns.c index 3c562dc9..58201a8d 100644 --- a/evdns.c +++ b/evdns.c @@ -45,12 +45,14 @@ #ifndef _EVENT_DNS_USE_GETTIMEOFDAY_FOR_ID #ifndef _EVENT_DNS_USE_OPENSSL_FOR_ID #ifndef _EVENT_DNS_USE_FTIME_FOR_ID +#ifndef _EVENT_DNS_USE_ARC4RANDOM_FOR_ID #error Must configure at least one id generation method. #error Please see the documentation. #endif #endif #endif #endif +#endif /* #define _POSIX_C_SOURCE 200507 */ #define _GNU_SOURCE @@ -1204,6 +1206,11 @@ default_transaction_id_fn(void) abort(); } #endif + +#ifdef _EVENT_DNS_USE_ARC4RANDOM_FOR_ID + trans_id = arc4random() & 0xffff; +#endif + return trans_id; }