Skip to content

Fix GH-16188: Handle references after fetching Exception properties #16196

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
wants to merge 2 commits into from

Conversation

arnaud-lb
Copy link
Member

Fixes GH-16188.

Exception assumes that the result of zend_read_property() have the right type, relying on property type hints. However the property value may also be a reference so we have to deref.

This was already done for protected properties as it's possible to assign them directly in sub-class, but not for private ones.

@arnaud-lb arnaud-lb marked this pull request as ready for review October 3, 2024 13:20

ZEND_PARSE_PARAMETERS_NONE();

ZVAL_COPY(return_value, GET_PROPERTY_SILENT(ZEND_THIS, ZEND_STR_PREVIOUS));
prop = GET_PROPERTY(ZEND_THIS, ZEND_STR_PREVIOUS);
Copy link
Member

@nielsdos nielsdos Oct 3, 2024

Choose a reason for hiding this comment

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

Is the change from silent to non-silent intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch!

Comment on lines 651 to 652
ZVAL_DEREF(prop);
ZVAL_COPY(return_value, prop);
Copy link
Member

Choose a reason for hiding this comment

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

We have ZVAL_COPY_DEREF, although I see pre-existing places with this pattern too...

@arnaud-lb arnaud-lb requested a review from nielsdos October 4, 2024 14:27
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

break;
}
}
zend_string_release_ex(fname, 0);

exception = ZEND_THIS;
/* Reset apply counts */
while (exception && Z_TYPE_P(exception) == IS_OBJECT && (base_ce = i_get_exception_base(Z_OBJ_P(exception))) && instanceof_function(Z_OBJCE_P(exception), base_ce)) {
while (Z_TYPE_P(exception) == IS_OBJECT && (base_ce = i_get_exception_base(Z_OBJ_P(exception))) && instanceof_function(Z_OBJCE_P(exception), base_ce)) {
Copy link
Member

Choose a reason for hiding this comment

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

Speaking of cleanup: we have a similar exception NULL-check on line 670. But that doesn't need to be in this PR.

arnaud-lb added a commit that referenced this pull request Oct 7, 2024
arnaud-lb added a commit that referenced this pull request Oct 7, 2024
* PHP-8.2:
  NEWS for GH-16196
  Handle references properties of the Exception class
arnaud-lb added a commit that referenced this pull request Oct 7, 2024
arnaud-lb added a commit that referenced this pull request Oct 7, 2024
* PHP-8.3:
  NEWS for GH-16196
  NEWS for GH-16196
  Handle references properties of the Exception class
arnaud-lb added a commit that referenced this pull request Oct 7, 2024
@arnaud-lb arnaud-lb closed this in c2115a4 Oct 7, 2024
arnaud-lb added a commit that referenced this pull request Oct 7, 2024
* PHP-8.4:
  NEWS for GH-16196
  NEWS for GH-16196
  NEWS for GH-16196
  Handle references properties of the Exception class
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.

2 participants