Skip to content

Commit 9dfbcd7

Browse files
committed
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()`.
1 parent 38ae522 commit 9dfbcd7

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 7.4.0RC3
44

5+
- FFI:
6+
. Fixed bug #78543 (is_callable() on FFI\CData throws Exception). (cmb)
57

68
19 Sep 2019, PHP 7.4.0RC2
79

Zend/zend_API.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3411,12 +3411,17 @@ static zend_always_inline zend_bool zend_is_callable_impl(zval *callable, zend_o
34113411
}
34123412
return 0;
34133413
case IS_OBJECT:
3414-
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) {
3415-
fcc->called_scope = fcc->calling_scope;
3416-
if (fcc == &fcc_local) {
3417-
zend_release_fcall_info_cache(fcc);
3414+
if (Z_OBJ_HANDLER_P(callable, get_closure)) {
3415+
if (Z_OBJ_HANDLER_P(callable, get_closure)(callable, &fcc->calling_scope, &fcc->function_handler, &fcc->object) == SUCCESS) {
3416+
fcc->called_scope = fcc->calling_scope;
3417+
if (fcc == &fcc_local) {
3418+
zend_release_fcall_info_cache(fcc);
3419+
}
3420+
return 1;
3421+
} else {
3422+
/* Discard exceptions thrown from Z_OBJ_HANDLER_P(callable, get_closure) */
3423+
zend_clear_exception();
34183424
}
3419-
return 1;
34203425
}
34213426
if (error) *error = estrdup("no array or string given");
34223427
return 0;

ext/ffi/tests/bug78543.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #78543 (is_callable() on FFI\CData throws Exception)
3+
--SKIPIF--
4+
<?php require_once('skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
$ffi = FFI::cdef(' struct test { int dummy; }; ');
8+
$test = $ffi->new('struct test');
9+
var_dump(is_callable($test));
10+
?>
11+
--EXPECT--
12+
bool(false)

0 commit comments

Comments
 (0)