]> granicus.if.org Git - php/commitdiff
Fix #78543: is_callable() on FFI\CData throws Exception
authorChristoph M. Becker <cmbecker69@gmx.de>
Wed, 18 Sep 2019 09:55:20 +0000 (11:55 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Thu, 19 Sep 2019 07:13:22 +0000 (09:13 +0200)
If `Z_OBJ_HANDLER_P(callable, get_closure)` throws, we must not let the
exeception pass to userland, if called through `is_callable()`.

NEWS
Zend/zend_API.c
ext/ffi/tests/bug78543.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index e7da8654d98a361aeb112a1081724a10401c6598..106cb28f3ea85075581d655ac0c13c7a9f349607 100644 (file)
--- 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
 
index 89e9c9d8490e11ce816f51f8e241fdf0c8d9e3e4..5be9d94dee3160cfbf42ebbea4560057010114e4 100644 (file)
@@ -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 (file)
index 0000000..e2f014d
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Bug #78543 (is_callable() on FFI\CData throws Exception)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+$ffi = FFI::cdef(' struct test { int dummy; }; ');
+$test = $ffi->new('struct test');
+var_dump(is_callable($test));
+?>
+--EXPECT--
+bool(false)