diff --git a/ext/random/config.m4 b/ext/random/config.m4 index 86f80224752..253979e3486 100644 --- a/ext/random/config.m4 +++ b/ext/random/config.m4 @@ -14,6 +14,11 @@ AC_CHECK_HEADERS([CommonCrypto/CommonRandom.h], [], [], #include ]) +dnl +dnl Mostly for non Linux systems +dnl +AC_CHECK_FUNCS([getrandom]) + dnl dnl Setup extension dnl diff --git a/ext/random/csprng.c b/ext/random/csprng.c index 106ec91affa..bbf12f567c1 100644 --- a/ext/random/csprng.c +++ b/ext/random/csprng.c @@ -46,7 +46,7 @@ #if HAVE_SYS_PARAM_H # include # if (__FreeBSD__ && __FreeBSD_version > 1200000) || (__DragonFly__ && __DragonFly_version >= 500700) || \ - defined(__sun) || (defined(__NetBSD__) && __NetBSD_Version__ >= 1000000000) + (defined(__sun) && defined(HAVE_GETRANDOM)) || (defined(__NetBSD__) && __NetBSD_Version__ >= 1000000000) # include # endif #endif @@ -98,7 +98,7 @@ PHPAPI zend_result php_random_bytes(void *bytes, size_t size, bool should_throw) #else size_t read_bytes = 0; # if (defined(__linux__) && defined(SYS_getrandom)) || (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || (defined(__DragonFly__) && __DragonFly_version >= 500700) || \ - defined(__sun) || (defined(__NetBSD__) && __NetBSD_Version__ >= 1000000000) + (defined(__sun) && defined(HAVE_GETRANDOM)) || (defined(__NetBSD__) && __NetBSD_Version__ >= 1000000000) /* Linux getrandom(2) syscall or FreeBSD/DragonFlyBSD/NetBSD getrandom(2) function * Being a syscall, implemented in the kernel, getrandom offers higher quality output * compared to the arc4random api albeit a fallback to /dev/urandom is considered.