]> granicus.if.org Git - libevent/commitdiff
Fix a couple of bugs in the BSD sysctl arc4seed logic
authorNick Mathewson <nickm@torproject.org>
Fri, 23 Apr 2010 20:08:09 +0000 (16:08 -0400)
committerNick Mathewson <nickm@torproject.org>
Fri, 23 Apr 2010 20:08:09 +0000 (16:08 -0400)
Of course, FreeBSD has its own arc4random() implementation, so this should
never actually be needed.  Still, it's good to paint the underside of the
wagon.

arc4random.c
configure.in

index a039711ff954c90fb0a578666abe2e2d835f49a0..5e04464308aed80becf5c02526baccf111346910 100644 (file)
@@ -201,16 +201,16 @@ arc4_seed_sysctl_linux(void)
 }
 #endif
 
-#if _EVENT_HAVE_DECL_CTL_KERN && _EVENT_HAVE_DECL_KERN_ARAND
+#if _EVENT_HAVE_DECL_CTL_KERN && _EVENT_HAVE_DECL_KERN_ARND
 #define TRY_SEED_SYSCTL_BSD
 static int
 arc4_seed_sysctl_bsd(void)
 {
        /* Based on code from William Ahern and from OpenBSD, this function
-        * tries to use the KERN_ARAND syscall to get entropy from the kernel.
+        * tries to use the KERN_ARND syscall to get entropy from the kernel.
         * This can work even if /dev/urandom is inaccessible for some reason
         * (e.g., we're running in a chroot). */
-       int mib[] = { CTL_KERN, KERN_ARAND };
+       int mib[] = { CTL_KERN, KERN_ARND };
        unsigned char buf[ADD_ENTROPY];
        size_t len, n;
        int i, any_set;
@@ -218,7 +218,7 @@ arc4_seed_sysctl_bsd(void)
        memset(buf, 0, sizeof(buf));
 
        len = sizeof(buf);
-       if (sysctl(mib, 2, rnd, &len, NULL, 0) == -1) {
+       if (sysctl(mib, 2, buf, &len, NULL, 0) == -1) {
                for (len = 0; len < sizeof(buf); len += sizeof(unsigned)) {
                        n = sizeof(unsigned);
                        if (n + len > sizeof(buf))
index 171801fecdc7da9a58bce1a1d4bca251f8ae74e6..e2177effa45d0ea8241f7f3c9b7100cd7a144332 100644 (file)
@@ -46,7 +46,7 @@ AC_ARG_ENABLE(debug-mode,
 AC_PROG_LIBTOOL
 
 dnl   Uncomment "AC_DISABLE_SHARED" to make shared librraries not get
-dnl   built by default.  You can also turn shared libs on and off from 
+dnl   built by default.  You can also turn shared libs on and off from
 dnl   the command line with --enable-shared and --disable-shared.
 dnl AC_DISABLE_SHARED
 AC_SUBST(LIBTOOL_DEPS)
@@ -159,8 +159,9 @@ if test "x$ac_cv_header_sys_time_h" = "xyes"; then
 fi
 
 if test "x$ac_cv_header_sys_sysctl_h" = "xyes"; then
-       AC_CHECK_DECLS([CTL_KERN, KERN_RANDOM, RANDOM_UUID, KERN_ARAND], [], [],
-          [[#include <sys/sysctl.h>]]
+       AC_CHECK_DECLS([CTL_KERN, KERN_RANDOM, RANDOM_UUID, KERN_ARND], [], [],
+          [[#include <sys/types.h>
+            #include <sys/sysctl.h>]]
        )
 fi