Merge branch 'PHP-8.2'

* PHP-8.2:
  Fix implicit/explicit port in mysqlnd

Closes GH-11990
This commit is contained in:
Kamil Tekiela 2023-08-16 20:34:33 +01:00
commit 7e4ca2e8d9
No known key found for this signature in database
GPG key ID: 0760BDAB1E89A1E3
4 changed files with 40 additions and 9 deletions

View file

@ -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!

View file

@ -542,6 +542,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); 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)) { 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; goto end;
} }
} }

View file

@ -725,19 +725,20 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn,
DBG_RETURN(PASS); DBG_RETURN(PASS);
} }
err: err:
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, "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) { if (transport.s) {
mnd_sprintf_free(transport.s); mnd_sprintf_free(transport.s);
transport.s = NULL; 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);
if (!conn->error_info->error_no) {
char * msg;
mnd_sprintf(&msg, 0, "%s (trying to connect via %s)",conn->error_info->error, conn->scheme.s);
SET_CLIENT_ERROR(conn->error_info, CR_CONNECTION_ERROR, UNKNOWN_SQLSTATE, msg);
mnd_sprintf_free(msg);
}
conn->m->free_contents(conn); conn->m->free_contents(conn);
MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_CONNECT_FAILURE); MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_CONNECT_FAILURE);
DBG_RETURN(FAIL); DBG_RETURN(FAIL);

View file

@ -569,7 +569,6 @@ MYSQLND_METHOD(mysqlnd_vio, enable_ssl)(MYSQLND_VIO * const net)
php_stream_xport_crypto_enable(net_stream, 1) < 0) php_stream_xport_crypto_enable(net_stream, 1) < 0)
{ {
DBG_ERR("Cannot connect to MySQL by using SSL"); 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); DBG_RETURN(FAIL);
} }
net->data->ssl = TRUE; net->data->ssl = TRUE;