From 5c9c275743df68dab0f7d08ab9002b04f40ab1a6 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 13 Aug 2024 18:12:50 +0100 Subject: [PATCH 1/2] 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 --- ext/random/config.m4 | 5 +++++ ext/random/random.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/random/config.m4 b/ext/random/config.m4 index a8e6d5a5689..bb4214a5c08 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/random.c b/ext/random/random.c index e30a04259fb..576c8412f52 100644 --- a/ext/random/random.c +++ b/ext/random/random.c @@ -48,7 +48,7 @@ #if HAVE_SYS_PARAM_H # include -# if (__FreeBSD__ && __FreeBSD_version > 1200000) || (__DragonFly__ && __DragonFly_version >= 500700) || defined(__sun) +# if (__FreeBSD__ && __FreeBSD_version > 1200000) || (__DragonFly__ && __DragonFly_version >= 500700) || (defined(__sun) && defined(HAVE_GETRANDOM)) # include # endif #endif @@ -511,7 +511,7 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw) #else size_t read_bytes = 0; ssize_t n; -# if (defined(__linux__) && defined(SYS_getrandom)) || (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || (defined(__DragonFly__) && __DragonFly_version >= 500700) || defined(__sun) +# if (defined(__linux__) && defined(SYS_getrandom)) || (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || (defined(__DragonFly__) && __DragonFly_version >= 500700) || (defined(__sun) && defined(HAVE_GETRANDOM)) /* Linux getrandom(2) syscall or FreeBSD/DragonFlyBSD getrandom(2) function*/ /* Keep reading until we get enough entropy */ while (read_bytes < size) { From 8c3f5f99f37697f7781f4abf632916f009064289 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 13 Aug 2024 21:01:20 +0100 Subject: [PATCH 2/2] [ci skip] update NEWS --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index f6cdb4b34f8..890e67592cc 100644 --- a/NEWS +++ b/NEWS @@ -54,6 +54,10 @@ PHP NEWS (zend_hash_num_elements() Zend/zend_hash.h)). (nielsdos) . Fixed bug GH-15210 use-after-free on watchpoint allocations. (nielsdos) +- Random: + . Fixed part of bug GH-15381, checking getrandom availability on solaris. + (David Carlier) + - Soap: . Fixed bug #55639 (Digest autentication dont work). (nielsdos) . Fix SoapFault property destruction. (nielsdos)