Skip to content

Add MAY_BE_NULL back to opcache info for stream_bucket_make_writeable #4567

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

Closed

Conversation

TysonAndre
Copy link
Contributor

This reverts one change in 001d434

A php snippet causing the function returning null in practice can be seen in
TysonAndre/php-src-ast-analysis#4

  • This repo also has some types that were missing from zend_func_info in
    the examples file (e.g. spl_object_hash, spl_object_id), that may be
    of interest - some entries are inaccurate and have extra/missing types. No other obvious bugs were seen.

The implementation of stream_bucket_make_writeable sets the return value
to null if the head of the bucket no longer exists.

Alternatively, change the ZVAL_NULL macro to something setting the return value to false in the implementation. (I don't use this functionality)

if ((brigade = (php_stream_bucket_brigade*)zend_fetch_resource(
				Z_RES_P(zbrigade), PHP_STREAM_BRIGADE_RES_NAME, le_bucket_brigade)) == NULL) {
	RETURN_FALSE;
}

ZVAL_NULL(return_value);

if (brigade->head && (bucket = php_stream_bucket_make_writeable(brigade->head))) {

This reverts one change in 001d434

An example of the function returning null in practice can be seen in
TysonAndre/php-src-ast-analysis#4

- This repo also has some types that were missing from zend_func_info in
  the examples file (e.g. spl_object_hash, spl_object_id), that may be
  of interest.

The implementation of stream_bucket_make_writeable sets the return value
to null if the head of the bucket no longer exists.

```c
if ((brigade = (php_stream_bucket_brigade*)zend_fetch_resource(
				Z_RES_P(zbrigade), PHP_STREAM_BRIGADE_RES_NAME, le_bucket_brigade)) == NULL) {
	RETURN_FALSE;
}

ZVAL_NULL(return_value);

if (brigade->head && (bucket = php_stream_bucket_make_writeable(brigade->head))) {
```
@@ -732,7 +732,7 @@ static const func_info_t func_infos[] = {
F1("str_rot13", MAY_BE_STRING),
F1("stream_get_filters", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING),
F0("stream_filter_register", MAY_BE_FALSE | MAY_BE_TRUE),
F1("stream_bucket_make_writeable", MAY_BE_FALSE | MAY_BE_OBJECT),
F1("stream_bucket_make_writeable", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_OBJECT),
Copy link
Member

Choose a reason for hiding this comment

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

While at it, the false type can be removed instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume that the return value is unused because zend_fetch_resource throws an exception by calling zend_type_error.

  • Are there any circumstances in the interpreter where calling RETURN_FALSE has a side effect even if an Error or Exception is thrown?
if ((brigade = (php_stream_bucket_brigade*)zend_fetch_resource(
				Z_RES_P(zbrigade), PHP_STREAM_BRIGADE_RES_NAME, le_bucket_brigade)) == NULL) {
	RETURN_FALSE;
}

The RETURN_NULL was added for clarity.
zend_fetch_resource always calls zend_type_error if it returned NULL.
@php-pulls php-pulls closed this in 50be2ec Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants