From daf7e18f9965eab0a01055cd0cef7a5741e6afad Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 28 Nov 2026 15:39:08 +0000 Subject: [PATCH] ext/random: php_random_bytes_ex() crash with CommonCrypto on macOS 10.11. Fix GH-25450 CCRandomGenerateBytes() was used whenever the CommonCrypto header was found. It is now used only when targeting macOS 10.12 or later. --- ext/random/csprng.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ext/random/csprng.c b/ext/random/csprng.c index 8b38985c6ac6..67bad499a92a 100644 --- a/ext/random/csprng.c +++ b/ext/random/csprng.c @@ -54,8 +54,12 @@ #endif #ifdef HAVE_COMMONCRYPTO_COMMONRANDOM_H -# include -# include +# include +# if MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 +# define PHP_USE_CCRANDOMGENERATEBYTES 1 +# include +# include +# endif #endif #if __has_feature(memory_sanitizer) @@ -74,7 +78,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_random_bytes_ex(void *bytes, size_ snprintf(errstr, errstr_size, "Failed to retrieve randomness from the operating system (BCryptGenRandom)"); return FAILURE; } -#elif defined(HAVE_COMMONCRYPTO_COMMONRANDOM_H) +#elif defined(PHP_USE_CCRANDOMGENERATEBYTES) /* * Purposely prioritized upon arc4random_buf for modern macOs releases * arc4random api on this platform uses `ccrng_generate` which returns