Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/ffi/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,7 @@ static void *zend_ffi_create_callback(zend_ffi_type *type, zval *value) /* {{{ *

if (!zend_is_callable_ex(value, NULL, 0, NULL, &fcc, &error)) {
zend_throw_error(zend_ffi_exception_ce, "Attempt to assign an invalid callback, %s", error);
efree(error);
return NULL;
}

Expand Down
18 changes: 18 additions & 0 deletions ext/ffi/tests/callback_invalid.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
FFI: assigning an invalid callback
--EXTENSIONS--
ffi
--INI--
ffi.enable=1
--FILE--
<?php
$ffi = FFI::cdef('typedef int (*fn)(void);');
$p = FFI::addr($ffi->new('fn'));
try {
$p[0] = 'nope';
} catch (FFI\Exception $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
FFI\Exception: Attempt to assign an invalid callback, function "nope" not found or invalid function name
Loading