Skip to content

Commit

Permalink
Merge branch 'PHP-8.4'
Browse files Browse the repository at this point in the history
* PHP-8.4:
  Fix phpGH-16397: Segmentation fault when comparing FFI object (php#16401)
  • Loading branch information
nielsdos committed Oct 14, 2024
2 parents 3401d55 + 7a7ab73 commit 8f1543a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ext/ffi/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2938,6 +2938,12 @@ static zend_function *zend_ffi_get_func(zend_object **obj, zend_string *name, co
}
/* }}} */

static int zend_fake_compare_objects(zval *o1, zval *o2)
{
zend_throw_error(zend_ffi_exception_ce, "Cannot compare FFI objects");
return ZEND_UNCOMPARABLE;
}

static zend_never_inline int zend_ffi_disabled(void) /* {{{ */
{
zend_throw_error(zend_ffi_exception_ce, "FFI API is restricted by \"ffi.enable\" configuration directive");
Expand Down Expand Up @@ -5443,7 +5449,7 @@ ZEND_MINIT_FUNCTION(ffi)
zend_ffi_handlers.has_dimension = zend_fake_has_dimension;
zend_ffi_handlers.unset_dimension = zend_fake_unset_dimension;
zend_ffi_handlers.get_method = zend_ffi_get_func;
zend_ffi_handlers.compare = NULL;
zend_ffi_handlers.compare = zend_fake_compare_objects;
zend_ffi_handlers.cast_object = zend_fake_cast_object;
zend_ffi_handlers.get_debug_info = NULL;
zend_ffi_handlers.get_closure = NULL;
Expand Down
15 changes: 15 additions & 0 deletions ext/ffi/tests/gh16397.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
GH-16397 (Segmentation fault when comparing FFI object)
--EXTENSIONS--
ffi
--FILE--
<?php
$ffi = FFI::cdef();
try {
var_dump($ffi != 1);
} catch (FFI\Exception $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Cannot compare FFI objects

0 comments on commit 8f1543a

Please sign in to comment.