-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix #79177: FFI doesn't handle well PHP exceptions within callback #6366
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
Conversation
When an FII callback function throws an unhandled exception, it makes not much sense to return value to the C code. Instead, we declare that the return value is undefined in this case, and let userland deal with that.
I'm not sure this makes sense. Do I understand right that this just leaves the return value uninitialized? |
Yes, this patch would.
|
I don't like the idea of leaving the return value uninitialized, that's almost certainly going to lead to UB. I don't think there is a really good solution to this problem, but I think the pragmatic solution would be to do something like |
That wouldn't solve the issue for Lines 715 to 722 in e1daa19
Maybe initialize the zval to a string with a single NUL byte in that case? However, that would somehow muddy this function. |
Welp, Lines 770 to 782 in e1daa19
|
I just realized that we're repeating #5120 here :) The discussion there came to the conclusion that there's really no way to handle this and we should convert the exception into a fatal error. |
This has been discussed and agreed upon in a previous PR[1]. [1] <php#5120>
Ah! Makes sense. |
@nikic, I was just trying this on 8.0, but php-src/Zend/zend_exceptions.c Line 976 in 793bf12
Is it correct to call zend_bailout(); immediately after zend_exception_error() ?
|
@cmb69 Actually, would it be sufficient to just cause an E_ERROR here? I think we already have code that automatically dumps pending exceptions when a fatal error occurs. |
Yes. That appears to be a good solution. |
When an FII callback function throws an unhandled exception, it makes
not much sense to return value to the C code. Instead, we declare that
the return value is undefined in this case, and let userland deal with
that.
Alternative fixes would be to clearly define the return value in this case, or to disallow unhandled exceptions in FFI callback functions altogether.