Skip to content

Commit 8f3c29a

Browse files
committed
Fix negotiaton of MySQL auth plugin
1 parent e88e83d commit 8f3c29a

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ PHP NEWS
2424
. Fixed bug #75579 (Interned strings buffer overflow may cause crash).
2525
(Dmitry)
2626

27+
- myslqnd
28+
. Fixed negotiaton of MySQL authenticaton plugin. (Johannes)
29+
2730
- PCRE:
2831
. Fixed bug #74183 (preg_last_error not returning error code after error).
2932
(Andrew Nester)

ext/mysqlnd/mysqlnd.c

+14-7
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,15 @@ mysqlnd_run_authentication(
596596
struct st_mysqlnd_authentication_plugin * auth_plugin = conn->m->fetch_auth_plugin_by_name(requested_protocol);
597597

598598
if (!auth_plugin) {
599-
php_error_docref(NULL, E_WARNING, "The server requested authentication method unknown to the client [%s]", requested_protocol);
600-
SET_CLIENT_ERROR(*conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, "The server requested authentication method unknown to the client");
601-
goto end;
599+
if (first_call) {
600+
mnd_pefree(requested_protocol, FALSE);
601+
requested_protocol = mnd_pestrdup(MYSQLND_DEFAULT_AUTH_PROTOCOL, FALSE);
602+
} else {
603+
php_error_docref(NULL, E_WARNING, "The server requested authentication method unknown to the client [%s]", requested_protocol);
604+
SET_CLIENT_ERROR(*conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, "The server requested authentication method unknown to the client");
605+
goto end;
606+
}
602607
}
603-
DBG_INF("plugin found");
604608

605609
{
606610
zend_uchar * switch_to_auth_protocol_data = NULL;
@@ -625,9 +629,12 @@ mysqlnd_run_authentication(
625629

626630
DBG_INF_FMT("salt(%d)=[%.*s]", plugin_data_len, plugin_data_len, plugin_data);
627631
/* The data should be allocated with malloc() */
628-
scrambled_data =
629-
auth_plugin->methods.get_auth_data(NULL, &scrambled_data_len, conn, user, passwd, passwd_len,
630-
plugin_data, plugin_data_len, options, &conn->net->data->options, mysql_flags);
632+
if (auth_plugin) {
633+
scrambled_data =
634+
auth_plugin->methods.get_auth_data(NULL, &scrambled_data_len, conn, user, passwd, passwd_len,
635+
plugin_data, plugin_data_len, options, &conn->net->data->options, mysql_flags);
636+
}
637+
631638
if (conn->error_info->error_no) {
632639
goto end;
633640
}

0 commit comments

Comments
 (0)