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
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 1 addition & 4 deletions ext/mysqli/mysqli_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,10 +969,6 @@ void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS, bool is_method)
MYSQLI_RESOURCE *mysqli_resource;
MY_MYSQL *mysql;

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}

if (is_method && (Z_MYSQLI_P(getThis()))->ptr) {
return;
}
Expand Down Expand Up @@ -1004,6 +1000,7 @@ void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS, bool is_method)
/* {{{ Initialize mysqli and return a resource for use with mysql_real_connect */
PHP_FUNCTION(mysqli_init)
{
ZEND_PARSE_PARAMETERS_NONE();
php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU, false);
}
/* }}} */
Expand Down
15 changes: 14 additions & 1 deletion ext/mysqli/mysqli_nonapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, bool is_real_connect, b
}
#endif

if (getThis() && !ZEND_NUM_ARGS() && in_ctor) {
if (in_ctor && !ZEND_NUM_ARGS()) {
ZEND_PARSE_PARAMETERS_NONE();

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

php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU, in_ctor);
return;
}
Expand All @@ -84,6 +91,11 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, bool is_real_connect, b
RETURN_THROWS();
}

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

if (object) {
ZEND_ASSERT(instanceof_function(Z_OBJCE_P(object), mysqli_link_class_entry));
mysqli_resource = (Z_MYSQLI_P(object))->ptr;
Expand Down Expand Up @@ -325,6 +337,7 @@ PHP_METHOD(mysqli, __construct)
/* {{{ Initialize mysqli and return a resource for use with mysql_real_connect */
PHP_METHOD(mysqli, init)
{
ZEND_PARSE_PARAMETERS_NONE();
php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
}
/* }}} */
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