From: Christoph M. Becker Date: Wed, 18 Sep 2019 09:55:20 +0000 (+0200) Subject: Fix #78543: is_callable() on FFI\CData throws Exception X-Git-Tag: php-7.4.0RC3~54 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9dfbcd7248012ac651a48eb871bfa58bb9e6c5d7;p=php Fix #78543: is_callable() on FFI\CData throws Exception If `Z_OBJ_HANDLER_P(callable, get_closure)` throws, we must not let the exeception pass to userland, if called through `is_callable()`. --- diff --git a/NEWS b/NEWS index e7da8654d9..106cb28f3e 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 7.4.0RC3 +- FFI: + . Fixed bug #78543 (is_callable() on FFI\CData throws Exception). (cmb) 19 Sep 2019, PHP 7.4.0RC2 diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 89e9c9d849..5be9d94dee 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -3411,12 +3411,17 @@ check_func: } return 0; case IS_OBJECT: - if (Z_OBJ_HANDLER_P(callable, get_closure) && Z_OBJ_HANDLER_P(callable, get_closure)(callable, &fcc->calling_scope, &fcc->function_handler, &fcc->object) == SUCCESS) { - fcc->called_scope = fcc->calling_scope; - if (fcc == &fcc_local) { - zend_release_fcall_info_cache(fcc); + if (Z_OBJ_HANDLER_P(callable, get_closure)) { + if (Z_OBJ_HANDLER_P(callable, get_closure)(callable, &fcc->calling_scope, &fcc->function_handler, &fcc->object) == SUCCESS) { + fcc->called_scope = fcc->calling_scope; + if (fcc == &fcc_local) { + zend_release_fcall_info_cache(fcc); + } + return 1; + } else { + /* Discard exceptions thrown from Z_OBJ_HANDLER_P(callable, get_closure) */ + zend_clear_exception(); } - return 1; } if (error) *error = estrdup("no array or string given"); return 0; diff --git a/ext/ffi/tests/bug78543.phpt b/ext/ffi/tests/bug78543.phpt new file mode 100644 index 0000000000..e2f014d7fc --- /dev/null +++ b/ext/ffi/tests/bug78543.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #78543 (is_callable() on FFI\CData throws Exception) +--SKIPIF-- + +--FILE-- +new('struct test'); +var_dump(is_callable($test)); +?> +--EXPECT-- +bool(false)