]> granicus.if.org Git - libevent/commitdiff
Use arc4random() for dns transaction ids where available. Patch taken from OpenBSD
authorNick Mathewson <nickm@torproject.org>
Sun, 15 Nov 2009 18:59:48 +0000 (18:59 +0000)
committerNick Mathewson <nickm@torproject.org>
Sun, 15 Nov 2009 18:59:48 +0000 (18:59 +0000)
svn:r1528

ChangeLog
configure.in
evdns.c

index 4834f424e28883b52b7c804512740b8b076fcc24..d369e524e37a6f43e4beda13eca268c1005dfa32 100644 (file)
--- 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:
index 2056d4111212890fec379ba39939eca5a4634802..9e45bbf822a9e430e0f525eed68c18393f322cc3 100644 (file)
@@ -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 is 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 3c562dc9c738c8bb742dc03cbfbb476a23efcb68..58201a8d2c45f8efa9370004a8c73fa7b819c39a 100644 (file)
--- a/evdns.c
+++ b/evdns.c
 #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;
 }