Skip to content

Fix implicit/explicit port in mysqlnd #11990

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

Merged
merged 1 commit into from
Aug 16, 2023
Merged
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
4 changes: 3 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.1.24


- MySQLnd:
. Fixed bug GH-10270 (Invalid error message when connection via SSL fails:
"trying to connect via (null)"). (Kamil Tekiela)

31 Aug 2023, PHP 8.1.23

Expand Down
29 changes: 29 additions & 0 deletions ext/mysqli/tests/gh8978.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
Bug GH-8267 (Invalid error message when connection via SSL fails)
--EXTENSIONS--
mysqli
--SKIPIF--
<?php
require_once 'skipifconnectfailure.inc';
?>
--FILE--
<?php
require_once "connect.inc";

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysql = mysqli_init();
// Ignore this warning as we are providing wrong information on purpose
mysqli_ssl_set($mysql, 'x509.key', 'x509.pem', 'x509.ca', null, null);
try {
// There should be no warning here, only exception
mysqli_real_connect($mysql, '127.0.0.1:3306', 'username', 'password', null, null, null, MYSQLI_CLIENT_SSL);
} catch (mysqli_sql_exception $e) {
echo $e->getMessage()."\n";
}

echo 'done!';
?>
--EXPECTF--
Warning: failed loading cafile stream: `x509.ca' in %s
Cannot connect to MySQL using SSL
done!
2 changes: 2 additions & 0 deletions ext/mysqlnd/mysqlnd_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ MYSQLND_METHOD(mysqlnd_command, enable_ssl)(MYSQLND_CONN_DATA * const conn, cons
conn->vio->data->m.set_client_option(conn->vio, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (const char *) &verify);

if (FAIL == conn->vio->data->m.enable_ssl(conn->vio)) {
SET_CONNECTION_STATE(&conn->state, CONN_QUIT_SENT);
SET_CLIENT_ERROR(conn->error_info, CR_CONNECTION_ERROR, UNKNOWN_SQLSTATE, "Cannot connect to MySQL using SSL");
goto end;
}
}
Expand Down
17 changes: 9 additions & 8 deletions ext/mysqlnd/mysqlnd_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, free_contents)(MYSQLND_CONN_DATA * conn)
mysqlnd_set_persistent_string(&conn->unix_socket, NULL, 0, pers);
DBG_INF_FMT("scheme=%s", conn->scheme.s);
mysqlnd_set_persistent_string(&conn->scheme, NULL, 0, pers);

if (conn->server_version) {
mnd_pefree(conn->server_version, pers);
conn->server_version = NULL;
Expand Down Expand Up @@ -726,19 +726,20 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn,
DBG_RETURN(PASS);
}
err:
if (transport.s) {
mnd_sprintf_free(transport.s);
transport.s = NULL;
}

DBG_ERR_FMT("[%u] %.128s (trying to connect via %s)", conn->error_info->error_no, conn->error_info->error, conn->scheme.s);
DBG_ERR_FMT("[%u] %.128s (trying to connect via %s)", conn->error_info->error_no, conn->error_info->error, transport.s ? transport.s : conn->scheme.s);
if (!conn->error_info->error_no) {
/* There was an unknown error if the connection failed but we have no error number */
char * msg;
mnd_sprintf(&msg, 0, "%s (trying to connect via %s)",conn->error_info->error, conn->scheme.s);
mnd_sprintf(&msg, 0, "Unknown error while trying to connect via %s", transport.s ? transport.s : conn->scheme.s);
SET_CLIENT_ERROR(conn->error_info, CR_CONNECTION_ERROR, UNKNOWN_SQLSTATE, msg);
mnd_sprintf_free(msg);
}

if (transport.s) {
mnd_sprintf_free(transport.s);
transport.s = NULL;
}

conn->m->free_contents(conn);
MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_CONNECT_FAILURE);
DBG_RETURN(FAIL);
Expand Down
1 change: 0 additions & 1 deletion ext/mysqlnd/mysqlnd_vio.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ MYSQLND_METHOD(mysqlnd_vio, enable_ssl)(MYSQLND_VIO * const net)
php_stream_xport_crypto_enable(net_stream, 1) < 0)
{
DBG_ERR("Cannot connect to MySQL by using SSL");
php_error_docref(NULL, E_WARNING, "Cannot connect to MySQL by using SSL");
DBG_RETURN(FAIL);
}
net->data->ssl = TRUE;
Expand Down