[php-src] PR #23814: ext/curl: fix use-after-free when setting a callback option from its own callback
| From: | jvoisin | Date: | Mon, 21 Sep 2026 10:04:40 +0000 |
| Subject: | [php-src] PR #23814: ext/curl: fix use-after-free when setting a callback option from its own callback | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-38657@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/23814
Author: jvoisin
php_curl_set_callable_handler() frees the previously registered callback with zend_fcc_dtor() before
installing the new one. The write/read/header/progress/ etc. callbacks run with ch->in_callback
set, so calling curl_setopt() with one of the callable options (CURLOPT_WRITEFUNCTION,
CURLOPT_READFUNCTION, ...) from inside such a callback destroys the fcc that is still executing. For
a non-closure callback such as [$obj, 'method'] whose object is only referenced by the
fcc, this releases $this while its method is still on the stack, resulting in a use-after-free
(closures are kept alive by the call frame, method receivers are not).
Reject setting a callable option while inside a callback, matching the existing in_callback guards
on curl_close() and curl_reset().