Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ext/mysqli/mysqli_nonapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, bool is_real_connect, b
}
#endif

if (getThis() && !ZEND_NUM_ARGS() && in_ctor) {
if (UNEXPECTED(in_ctor && (Z_MYSQLI_P(object))->ptr)) {
zend_throw_error(NULL, "Cannot call constructor twice");
return;
}

if (in_ctor && !ZEND_NUM_ARGS()) {
php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU, in_ctor);
return;
}
Expand All @@ -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.

ZEND_ASSERT(instanceof_function(Z_OBJCE_P(object), mysqli_link_class_entry));
#endif
mysqli_resource = (Z_MYSQLI_P(object))->ptr;
if (mysqli_resource && mysqli_resource->ptr) {
mysql = (MY_MYSQL*) mysqli_resource->ptr;
Expand Down
16 changes: 16 additions & 0 deletions ext/mysqli/tests/gh17900.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
GH-17900 (Assertion failure ext/mysqli/mysqli_prop.c)
--EXTENSIONS--
mysqli
--FILE--
<?php
mysqli_report(MYSQLI_REPORT_OFF);
$mysqli = new mysqli();
try {
$mysqli->__construct('doesnotexist');
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Cannot call constructor twice
4 changes: 2 additions & 2 deletions ext/mysqli/tests/mysqli_incomplete_initialization.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ $mysqli->close();

?>
--EXPECTF--
Fatal error: Uncaught Error: mysqli object is not fully initialized in %s:%d
Fatal error: Uncaught Error: Cannot call constructor twice in %s:%d
Stack trace:
#0 %s(%d): mysqli->close()
#0 %s(%d): mysqli->__construct('doesnotexist')
#1 {main}
thrown in %s on line %d
Loading