[php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Mon, 21 Sep 2026 17:55:23 +0000
Subject: [php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141342@lists.php.net to get a copy of this message
Author: Weilin Du (LamentXU123) Date: 2026-09-22T01:53:19+08:00 Commit: https://github.com/php/php-src/commit/6d22c49dde466c0c20b183b40d9337ae1f32dbe3 Raw diff: https://github.com/php/php-src/commit/6d22c49dde466c0c20b183b40d9337ae1f32dbe3.diff Merge branch 'PHP-8.4' into PHP-8.5 Propagate the backport of PR #23814 from PHP-8.4 to PHP-8.5. * PHP-8.4: Backport: reject cURL callback changes from callbacks (#23814) Changed paths: A ext/curl/tests/curl_setopt_callback_reentrancy.phpt M ext/curl/interface.c Diff: diff --git a/ext/curl/interface.c b/ext/curl/interface.c index d8398c368c3c..c78f9686c467 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -1575,8 +1575,14 @@ PHP_FUNCTION(curl_copy_handle) } /* }}} */ -static bool php_curl_set_callable_handler(zend_fcall_info_cache *const handler_fcc, zval *callable, bool is_array_config, const char *option_name) +static bool php_curl_set_callable_handler(php_curl *ch, zend_fcall_info_cache *const handler_fcc, zval *callable, bool is_array_config, const char *option_name) { + /* Replacing a callback would free the fcc that is still executing on the stack. */ + if (ch->in_callback) { + zend_throw_error(NULL, "%s(): Attempt to set the %s option from a callback", get_active_function_name(), option_name); + return false; + } + if (ZEND_FCC_INITIALIZED(*handler_fcc)) { zend_fcc_dtor(handler_fcc); } @@ -1600,7 +1606,7 @@ static bool php_curl_set_callable_handler(zend_fcall_info_cache *const handler_f #define HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(curl_ptr, constant_no_function, handler_type, default_method) \ case constant_no_function##FUNCTION: { \ - bool result = php_curl_set_callable_handler(&curl_ptr->handlers.handler_type->fcc, zvalue, is_array_config, #constant_no_function "FUNCTION"); \ + bool result = php_curl_set_callable_handler(curl_ptr, &curl_ptr->handlers.handler_type->fcc, zvalue, is_array_config, #constant_no_function "FUNCTION"); \ if (!result) { \ curl_ptr->handlers.handler_type->method = default_method; \ return FAILURE; \ @@ -1615,7 +1621,7 @@ static bool php_curl_set_callable_handler(zend_fcall_info_cache *const handler_f #define HANDLE_CURL_OPTION_CALLABLE(curl_ptr, constant_no_function, handler_fcc, c_callback) \ case constant_no_function##FUNCTION: { \ - bool result = php_curl_set_callable_handler(&curl_ptr->handler_fcc, zvalue, is_array_config, #constant_no_function "FUNCTION"); \ + bool result = php_curl_set_callable_handler(curl_ptr, &curl_ptr->handler_fcc, zvalue, is_array_config, #constant_no_function "FUNCTION"); \ if (!result) { \ return FAILURE; \ } \ diff --git a/ext/curl/tests/curl_setopt_callback_reentrancy.phpt b/ext/curl/tests/curl_setopt_callback_reentrancy.phpt new file mode 100644 index 000000000000..662c42ac6ed6 --- /dev/null +++ b/ext/curl/tests/curl_setopt_callback_reentrancy.phpt @@ -0,0 +1,38 @@ +--TEST-- +GH-23814 (Setting a callback option from within a curl callback is rejected) +--EXTENSIONS-- +curl +--SKIPIF-- +<?php +if (!in_array('file', curl_version()['protocols'], true)) { + die('skip file protocol not supported'); +} +?> +--FILE-- +<?php + +$handle = curl_init('file://' . __FILE__); +$callback = static function (CurlHandle $handle, string $data): int { + try { + curl_setopt($handle, CURLOPT_WRITEFUNCTION, static fn($handle, $data) => strlen($data)); + } catch (Error $error) { + echo $error->getMessage(), "\n"; + } + + try { + curl_setopt_array($handle, [CURLOPT_WRITEFUNCTION => null]); + } catch (Error $error) { + echo $error->getMessage(), "\n"; + } + + return strlen($data); +}; +curl_setopt($handle, CURLOPT_WRITEFUNCTION, $callback); +var_dump(curl_exec($handle)); +var_dump(curl_setopt($handle, CURLOPT_WRITEFUNCTION, null)); +?> +--EXPECT-- +curl_setopt(): Attempt to set the CURLOPT_WRITEFUNCTION option from a callback +curl_setopt_array(): Attempt to set the CURLOPT_WRITEFUNCTION option from a callback +bool(true) +bool(true)

« previous php.cvs (#141342) next »