com php-src: Use arc4random on OpenBSD 5.5+ and NetBSD 7+: ext/standard/config.m4 ext/standard/random.c

From: Date: Fri, 30 Oct 2015 19:08:20 +0000
Subject: com php-src: Use arc4random on OpenBSD 5.5+ and NetBSD 7+: ext/standard/config.m4 ext/standard/random.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-89574@lists.php.net to get a copy of this message
Commit: faf835be2bd4db8e57e2529a8022b208cd9201b2 Author: Leigh <leigh@php.net> Fri, 30 Oct 2015 19:08:20 +0000 Parents: c4297a5a2949c11a8f49bc90a661ba74f2f03f03 Branches: PHP-7.0 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=faf835be2bd4db8e57e2529a8022b208cd9201b2 Log: Use arc4random on OpenBSD 5.5+ and NetBSD 7+ As discussed with @weltling, keeping arc4random on the condition that the OS has a solid implementation of it Changed paths: M ext/standard/config.m4 M ext/standard/random.c Diff: diff --git a/ext/standard/config.m4 b/ext/standard/config.m4 index f41df7e..c435f96 100644 --- a/ext/standard/config.m4 +++ b/ext/standard/config.m4 @@ -593,6 +593,11 @@ dnl AC_CHECK_HEADERS([atomic.h]) dnl +dnl Check for arc4random on BSD systems +dnl +AC_CHECK_DECLS([arc4random_buf]) + +dnl dnl Check for getrandom on newer Linux kernels dnl AC_CHECK_DECLS([getrandom]) diff --git a/ext/standard/random.c b/ext/standard/random.c index fd730d1..7056879 100644 --- a/ext/standard/random.c +++ b/ext/standard/random.c @@ -33,6 +33,9 @@ #ifdef __linux__ # include <sys/syscall.h> #endif +#if defined(__OpenBSD__) || defined(__NetBSD__) +# include <sys/param.h> +#endif #ifdef ZTS int random_globals_id; @@ -87,6 +90,8 @@ static int php_random_bytes(void *bytes, size_t size) zend_throw_exception(zend_ce_exception, "Could not gather sufficient random data", 0); return FAILURE; } +#elif HAVE_DECL_ARC4RANDOM_BUF && ((defined(__OpenBSD__) && OpenBSD >= 201405) || (defined(__NetBSD__) && __NetBSD_Version__ >= 700000001)) + arc4random_buf(bytes, size); #elif HAVE_DECL_GETRANDOM /* Linux getrandom(2) syscall */ size_t read_bytes = 0;

« previous php.cvs (#89574) next »