Skip to content

Commit 03ee36d

Browse files
committed
Fix unix socket check during caching_sha2_password
The fact that conn->unix_socket is set does not mean that a Unix socket is actually in use -- this member is set in a default configuration. Instead check whether a unix_socket stream ops is used.
1 parent 6225137 commit 03ee36d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

ext/mysqlnd/mysqlnd_auth.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,14 @@ mysqlnd_caching_sha2_get_and_use_key(MYSQLND_CONN_DATA *conn,
10321032
}
10331033
/* }}} */
10341034

1035+
static int is_secure_transport(MYSQLND_CONN_DATA *conn) {
1036+
if (conn->vio->data->ssl) {
1037+
return 1;
1038+
}
1039+
1040+
return strcmp(conn->vio->data->stream->ops->label, "unix_socket") == 0;
1041+
}
1042+
10351043
/* {{{ mysqlnd_caching_sha2_handle_server_response */
10361044
static enum_func_status
10371045
mysqlnd_caching_sha2_handle_server_response(struct st_mysqlnd_authentication_plugin *self,
@@ -1063,13 +1071,13 @@ mysqlnd_caching_sha2_handle_server_response(struct st_mysqlnd_authentication_plu
10631071
DBG_INF("fast path succeeded");
10641072
DBG_RETURN(PASS);
10651073
case 4:
1066-
if (conn->vio->data->ssl || conn->unix_socket.s) {
1067-
DBG_INF("fast path failed, doing full auth via SSL");
1074+
if (is_secure_transport(conn)) {
1075+
DBG_INF("fast path failed, doing full auth via secure transport");
10681076
result_packet.password = (zend_uchar *)passwd;
10691077
result_packet.password_len = passwd_len + 1;
10701078
PACKET_WRITE(conn, &result_packet);
10711079
} else {
1072-
DBG_INF("fast path failed, doing full auth without SSL");
1080+
DBG_INF("fast path failed, doing full auth via insecure transport");
10731081
result_packet.password_len = mysqlnd_caching_sha2_get_and_use_key(conn, auth_plugin_data, auth_plugin_data_len, &result_packet.password, passwd, passwd_len);
10741082
PACKET_WRITE(conn, &result_packet);
10751083
efree(result_packet.password);

ext/mysqlnd/mysqlnd_connection.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,9 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn,
671671

672672
{
673673
const MYSQLND_CSTRING scheme = { transport.s, transport.l };
674-
/* This will be overwritten below with a copy, but we can use it during authentication */
675-
conn->unix_socket.s = (char *)socket_or_pipe.s;
676674
if (FAIL == conn->m->connect_handshake(conn, &scheme, &username, &password, &database, mysql_flags)) {
677-
conn->unix_socket.s = NULL;
678675
goto err;
679676
}
680-
conn->unix_socket.s = NULL;
681677
}
682678

683679
{

0 commit comments

Comments
 (0)