Skip to content

Commit f1e5c63

Browse files
committed
Checks getrandom availability on solaris.
To fix part of GH-15381. gcc nor clang provides a constant to distinguish illumos and solaris not the system provides a kernel version stamp like the BSD. thus, we simply check the symbol and remaing purposely conservative in the existing logic, using it only for solaris to avoid unexpected breakages for other systems. would need a different fix for higher branches. Close GH-15390
1 parent 0b61b8d commit f1e5c63

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

ext/random/config.m4

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ AC_CHECK_HEADERS([CommonCrypto/CommonRandom.h], [], [],
1414
#include <CommonCrypto/CommonCryptoError.h>
1515
])
1616

17+
dnl
18+
dnl Mostly for non Linux systems
19+
dnl
20+
AC_CHECK_FUNCS([getrandom])
21+
1722
dnl
1823
dnl Setup extension
1924
dnl

ext/random/csprng.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#if HAVE_SYS_PARAM_H
4747
# include <sys/param.h>
4848
# if (__FreeBSD__ && __FreeBSD_version > 1200000) || (__DragonFly__ && __DragonFly_version >= 500700) || \
49-
defined(__sun) || (defined(__NetBSD__) && __NetBSD_Version__ >= 1000000000)
49+
(defined(__sun) && defined(HAVE_GETRANDOM)) || (defined(__NetBSD__) && __NetBSD_Version__ >= 1000000000)
5050
# include <sys/random.h>
5151
# endif
5252
#endif
@@ -98,7 +98,7 @@ PHPAPI zend_result php_random_bytes(void *bytes, size_t size, bool should_throw)
9898
#else
9999
size_t read_bytes = 0;
100100
# if (defined(__linux__) && defined(SYS_getrandom)) || (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || (defined(__DragonFly__) && __DragonFly_version >= 500700) || \
101-
defined(__sun) || (defined(__NetBSD__) && __NetBSD_Version__ >= 1000000000)
101+
(defined(__sun) && defined(HAVE_GETRANDOM)) || (defined(__NetBSD__) && __NetBSD_Version__ >= 1000000000)
102102
/* Linux getrandom(2) syscall or FreeBSD/DragonFlyBSD/NetBSD getrandom(2) function
103103
* Being a syscall, implemented in the kernel, getrandom offers higher quality output
104104
* compared to the arc4random api albeit a fallback to /dev/urandom is considered.

0 commit comments

Comments
 (0)