From b674db54ca9a538703e1e3f129faee1f5fba70ef Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Wed, 7 May 2014 08:58:47 -0700 Subject: [PATCH] [v9_10] check for arc4random_addrandom() 3840. [port] Check for arc4random_addrandom() before using it; it's been removed from OpenBSD 5.5. [RT #35907] (cherry picked from commit 1ea6e09c376b1351c614474a88675b1a9bda6571) --- CHANGES | 3 +++ acconfig.h | 3 +++ config.h.in | 3 +++ configure | 9 ++++++++- configure.in | 4 +++- lib/isc/random.c | 10 +++++++++- 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index cd04d58202..7a40a28152 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +3840. [port] Check for arc4random_addrandom() before using it; + it's been removed from OpenBSD 5.5. [RT #35907] + 3839. [test] Use only posix-compatible shell in system tests. [RT #35625] diff --git a/acconfig.h b/acconfig.h index 34feb556a0..125d18e466 100644 --- a/acconfig.h +++ b/acconfig.h @@ -73,6 +73,9 @@ /** define if arc4random() exists */ #undef HAVE_ARC4RANDOM +/** define if arc4random_addrandom() exists */ +#undef HAVE_ARC4RANDOM_ADDRANDOM + /** * define if pthread_setconcurrency() should be called to tell the * OS how many threads we might want to run. diff --git a/config.h.in b/config.h.in index 0f6658fdf3..09d77b4265 100644 --- a/config.h.in +++ b/config.h.in @@ -73,6 +73,9 @@ /** define if arc4random() exists */ #undef HAVE_ARC4RANDOM +/** define if arc4random_addrandom() exists */ +#undef HAVE_ARC4RANDOM_ADDRANDOM + /** * define if pthread_setconcurrency() should be called to tell the * OS how many threads we might want to run. diff --git a/configure b/configure index ee3c490a03..21a014c2b3 100755 --- a/configure +++ b/configure @@ -14113,7 +14113,8 @@ fi # -# Do we have arc4random() ? +# Do we have arc4random(), etc ? arc4random_addrandom() has been removed +# from OpenBSD 5.5 onwards. # ac_fn_c_check_func "$LINENO" "arc4random" "ac_cv_func_arc4random" if test "x$ac_cv_func_arc4random" = xyes; then : @@ -14121,6 +14122,12 @@ if test "x$ac_cv_func_arc4random" = xyes; then : fi +ac_fn_c_check_func "$LINENO" "arc4random_addrandom" "ac_cv_func_arc4random_addrandom" +if test "x$ac_cv_func_arc4random_addrandom" = xyes; then : + $as_echo "#define HAVE_ARC4RANDOM_ADDRANDOM 1" >>confdefs.h + +fi + # # Begin pthreads checking. diff --git a/configure.in b/configure.in index 43de6e6ebc..6bca7fe1ce 100644 --- a/configure.in +++ b/configure.in @@ -967,9 +967,11 @@ fi AC_SUBST(CHECK_DSA) # -# Do we have arc4random() ? +# Do we have arc4random(), etc ? arc4random_addrandom() has been removed +# from OpenBSD 5.5 onwards. # AC_CHECK_FUNC(arc4random, AC_DEFINE(HAVE_ARC4RANDOM)) +AC_CHECK_FUNC(arc4random_addrandom, AC_DEFINE(HAVE_ARC4RANDOM_ADDRANDOM)) sinclude(config.threads.in)dnl diff --git a/lib/isc/random.c b/lib/isc/random.c index 4c48e60fd7..624ac1bad9 100644 --- a/lib/isc/random.c +++ b/lib/isc/random.c @@ -67,8 +67,16 @@ isc_random_seed(isc_uint32_t seed) #ifndef HAVE_ARC4RANDOM srand(seed); -#else +#elif defined(HAVE_ARC4RANDOM_ADDRANDOM) arc4random_addrandom((u_char *) &seed, sizeof(isc_uint32_t)); +#else + /* + * If arcrandom() is available and no corresponding seeding + * function arc4random_addrandom() is available, no seeding is + * done on such platforms (e.g., OpenBSD 5.5). This is because + * the OS itself is supposed to seed the RNG and it is assumed + * that no explicit seeding is required. + */ #endif }