Skip to content

Fix GH-17900 and GH-8084 #17908

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

nielsdos
Copy link
Member

@nielsdos nielsdos commented Feb 23, 2025

Calling the constructor twice has no real world benefit. Block it to fix these two issues.
We also clean up the constructor code a bit:
in_ctor implies object exists, and some conditions are only possible with object set.

Closes GH-17900.
Closes GH-8084.

@nielsdos nielsdos marked this pull request as draft February 23, 2025 16:56
@nielsdos nielsdos force-pushed the mysqli-no-double-construct branch from 229beda to 4205c31 Compare February 23, 2025 18:07
@nielsdos nielsdos marked this pull request as ready for review February 23, 2025 18:07
Calling the constructor twice has no real world benefit.
Block it to fix these two issues.
We also clean up the constructor code a bit:
- `in_ctor` implies `object` exist.
- We surround the instance check with ZEND_DEBUG to avoid a runtime
  penalty.

Closes phpGH-17900.
Closes phpGH-8084.
@@ -85,7 +90,9 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, bool is_real_connect, b
}

if (object) {
#if ZEND_DEBUG
Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't part of the fix but initially I had changed the code in this if branch as well and put this in an #if to avoid the overhead, I can drop this or commit this separately

Copy link
Member

Choose a reason for hiding this comment

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

I don't think the assert should be in #if.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think the assert should be in #if.

I can drop this. The motivation is that the call to instanceof_function_slow will still be done even in release builds, but it's not that big of a deal.

Copy link
Member

@kamil-tekiela kamil-tekiela left a comment

Choose a reason for hiding this comment

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

It makes sense to me.

As an aside, __construct should be blocked the same way for the other 2 classes.

I also wonder why mysqli_common_connect even accepts in_ctor. Wouldn't it make more sense to have this check outside of this method in PHP_METHOD(mysqli, __construct)?

@nielsdos
Copy link
Member Author

As an aside, __construct should be blocked the same way for the other 2 classes.

Perhaps, for a follow-up maybe.

I also wonder why mysqli_common_connect even accepts in_ctor. Wouldn't it make more sense to have this check outside of this method in PHP_METHOD(mysqli, __construct)?

If we do this prior to argument parsing, we create an arginfo/ZPP consistency violation; because if the wrong arguments are passed these should throw prior to the double constructor exception being thrown.

@kamil-tekiela
Copy link
Member

If we do this prior to argument parsing, we create an arginfo/ZPP consistency violation; because if the wrong arguments are passed these should throw prior to the double constructor exception being thrown.

But isn't the check you added done prior to parsing arguments anyway?

@nielsdos
Copy link
Member Author

If we do this prior to argument parsing, we create an arginfo/ZPP consistency violation; because if the wrong arguments are passed these should throw prior to the double constructor exception being thrown.

But isn't the check you added done prior to parsing arguments anyway?

Ah damn, I'm sorry. I thought I did this differently, I shouldn't work on multiple things at the same time...
I pushed the right fix now I think.

@nielsdos nielsdos closed this in 2b6c9b6 Feb 24, 2025
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.

Assertion failure ext/mysqli/mysqli_prop.c Calling mysqli_stmt constructor leaks memory
2 participants