Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GH-16397: Segmentation fault when comparing FFI object #16401

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

nielsdos
Copy link
Member

compare is a required handler [1], but this handler was set to NULL. Throw an exception when trying to compare FFI objects.

[1] https://github.com/php/php-src/blob/35c8a010c6633a2a1ba7c16a0cf83affa07b819e/Zend/zend_object_handlers.h#L231C1-L231C64

@nielsdos nielsdos requested a review from dstogov as a code owner October 12, 2024 20:17
@nielsdos nielsdos linked an issue Oct 12, 2024 that may be closed by this pull request
Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

$ffi = FFI::cdef();
try {
var_dump($ffi != 1);
} catch (Error $e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be more specific by catching only FFI\Exception.

ext/ffi/ffi.c Outdated Show resolved Hide resolved
ext/ffi/ffi.c Outdated
@@ -2922,6 +2922,12 @@ static zend_function *zend_ffi_get_func(zend_object **obj, zend_string *name, co
}
/* }}} */

static int zend_ffi_compare_objects(zval *o1, zval *o2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would name this zend _fake_compare_objects for consistency.

nielsdos added a commit to nielsdos/php-src that referenced this pull request Oct 14, 2024
`compare` is a required handler [1], but this handler was set to NULL.
Throw an exception when trying to compare FFI objects.

[1] https://github.com/php/php-src/blob/35c8a010c6633a2a1ba7c16a0cf83affa07b819e/Zend/zend_object_handlers.h#L231C1-L231C64

Closes phpGH-16401.
@nielsdos nielsdos force-pushed the fix-16397 branch 2 times, most recently from eb81841 to ef6c84e Compare October 14, 2024 16:43
`compare` is a required handler [1], but this handler was set to NULL.
Throw an exception when trying to compare FFI objects.

[1] https://github.com/php/php-src/blob/35c8a010c6633a2a1ba7c16a0cf83affa07b819e/Zend/zend_object_handlers.h#L231C1-L231C64

Closes phpGH-16401.
@nielsdos nielsdos merged commit ec8a24f into php:PHP-8.2 Oct 14, 2024
8 checks passed
nielsdos added a commit that referenced this pull request Oct 14, 2024
* PHP-8.2:
  Fix GH-16397: Segmentation fault when comparing FFI object (#16401)
nielsdos added a commit that referenced this pull request Oct 14, 2024
* PHP-8.3:
  Fix GH-16397: Segmentation fault when comparing FFI object (#16401)
nielsdos added a commit that referenced this pull request Oct 14, 2024
* PHP-8.4:
  Fix GH-16397: Segmentation fault when comparing FFI object (#16401)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation fault when comparing FFI object
4 participants