From 2a2c50cb77a9218a02eb14d7ba6bce4863da2acb Mon Sep 17 00:00:00 2001 From: Dharman Date: Mon, 21 Dec 2020 16:45:14 +0000 Subject: [PATCH 1/5] Fix first batch of warnings --- ext/mysqlnd/mysqlnd_auth.c | 11 ++++++++--- ext/mysqlnd/mysqlnd_commands.c | 18 +++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ext/mysqlnd/mysqlnd_auth.c b/ext/mysqlnd/mysqlnd_auth.c index e3a21dfae6abd..1dbd1f9ebdddd 100644 --- a/ext/mysqlnd/mysqlnd_auth.c +++ b/ext/mysqlnd/mysqlnd_auth.c @@ -81,8 +81,10 @@ mysqlnd_run_authentication( mnd_pefree(requested_protocol, FALSE); requested_protocol = mnd_pestrdup(MYSQLND_DEFAULT_AUTH_PROTOCOL, FALSE); } else { - php_error_docref(NULL, E_WARNING, "The server requested authentication method unknown to the client [%s]", requested_protocol); - SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, "The server requested authentication method unknown to the client"); + char * msg; + mnd_sprintf(&msg, 0, "The server requested authentication method unknown to the client [%s]", requested_protocol); + SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, msg); + mnd_sprintf_free(msg); goto end; } } @@ -1271,7 +1273,10 @@ mysqlnd_caching_sha2_handle_server_response(struct st_mysqlnd_authentication_plu // The server tried to send a key, which we didn't expect // fall-through default: - php_error_docref(NULL, E_WARNING, "Unexpected server response while doing caching_sha2 auth: %i", result_packet.response_code); + char * msg; + mnd_sprintf(&msg, 0, "Unexpected server response while doing caching_sha2 auth: %i", result_packet.response_code); + SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, msg); + mnd_sprintf_free(msg); } DBG_RETURN(PASS); diff --git a/ext/mysqlnd/mysqlnd_commands.c b/ext/mysqlnd/mysqlnd_commands.c index 57ac24b8c5eb1..15beda9a6f80e 100644 --- a/ext/mysqlnd/mysqlnd_commands.c +++ b/ext/mysqlnd/mysqlnd_commands.c @@ -632,11 +632,11 @@ MYSQLND_METHOD(mysqlnd_command, handshake)(MYSQLND_CONN_DATA * const conn, const SET_CLIENT_ERROR(conn->error_info, greet_packet.error_no, greet_packet.sqlstate, greet_packet.error); goto err; } else if (greet_packet.pre41) { - DBG_ERR_FMT("Connecting to 3.22, 3.23 & 4.0 is not supported. Server is %-.32s", greet_packet.server_version); - php_error_docref(NULL, E_WARNING, "Connecting to 3.22, 3.23 & 4.0 " - " is not supported. Server is %-.32s", greet_packet.server_version); - SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, - "Connecting to 3.22, 3.23 & 4.0 servers is not supported"); + char * msg; + mnd_sprintf(&msg, 0, "Connecting to 3.22, 3.23 & 4.0 is not supported. Server is %-.32s", greet_packet.server_version); + DBG_ERR(msg); + SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, msg); + mnd_sprintf_free(msg); goto err; } @@ -646,10 +646,10 @@ MYSQLND_METHOD(mysqlnd_command, handshake)(MYSQLND_CONN_DATA * const conn, const conn->greet_charset = mysqlnd_find_charset_nr(greet_packet.charset_no); if (!conn->greet_charset) { - php_error_docref(NULL, E_WARNING, - "Server sent charset (%d) unknown to the client. Please, report to the developers", greet_packet.charset_no); - SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, - "Server sent charset unknown to the client. Please, report to the developers"); + char * msg; + mnd_sprintf(&msg, 0, "Server sent charset (%d) unknown to the client. Please, report to the developers", greet_packet.charset_no); + SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, msg); + mnd_sprintf_free(msg); goto err; } From 4f4121c8e66b9bf9dbc4aa506e0e9914c2d74f77 Mon Sep 17 00:00:00 2001 From: Dharman Date: Mon, 21 Dec 2020 16:48:57 +0000 Subject: [PATCH 2/5] Not sure if the scheme is required but it might be useful --- ext/mysqlnd/mysqlnd_connection.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ext/mysqlnd/mysqlnd_connection.c b/ext/mysqlnd/mysqlnd_connection.c index 4d25488ee6c2b..2414e415cb329 100644 --- a/ext/mysqlnd/mysqlnd_connection.c +++ b/ext/mysqlnd/mysqlnd_connection.c @@ -774,8 +774,10 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn, 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) { - SET_CLIENT_ERROR(conn->error_info, CR_CONNECTION_ERROR, UNKNOWN_SQLSTATE, conn->error_info->error); - php_error_docref(NULL, E_WARNING, "[%u] %.128s (trying to connect via %s)", conn->error_info->error_no, conn->error_info->error, conn->scheme.s); + 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); From 6608a725d113493ac46886addfaee9ec75a94da8 Mon Sep 17 00:00:00 2001 From: Dharman Date: Mon, 21 Dec 2020 17:07:58 +0000 Subject: [PATCH 3/5] This should be a client error rather than PHP error --- ext/mysqlnd/mysqlnd_connection.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/mysqlnd/mysqlnd_connection.c b/ext/mysqlnd/mysqlnd_connection.c index 2414e415cb329..1f4885a3556c8 100644 --- a/ext/mysqlnd/mysqlnd_connection.c +++ b/ext/mysqlnd/mysqlnd_connection.c @@ -2102,9 +2102,9 @@ MYSQLND_METHOD(mysqlnd_conn_data, tx_begin)(MYSQLND_CONN_DATA * conn, const unsi } ret = conn->m->query(conn, query, query_len); mnd_sprintf_free(query); - if (ret && mode & (TRANS_START_READ_WRITE | TRANS_START_READ_ONLY) && - mysqlnd_stmt_errno(conn) == 1064) { - php_error_docref(NULL, E_WARNING, "This server version doesn't support 'READ WRITE' and 'READ ONLY'. Minimum 5.6.5 is required"); + if (ret && mode & (TRANS_START_READ_WRITE | TRANS_START_READ_ONLY) && mysqlnd_stmt_errno(conn) == 1064) { + SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, + "This server version doesn't support 'READ WRITE' and 'READ ONLY'. Minimum 5.6.5 is required"); break; } } From 6d6beab2a380715be583426638d796b46a4c88d2 Mon Sep 17 00:00:00 2001 From: Dharman Date: Mon, 21 Dec 2020 17:17:33 +0000 Subject: [PATCH 4/5] Same as client error --- ext/mysqlnd/mysqlnd_loaddata.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/mysqlnd/mysqlnd_loaddata.c b/ext/mysqlnd/mysqlnd_loaddata.c index 6cd100ab744ce..677378f5cddf8 100644 --- a/ext/mysqlnd/mysqlnd_loaddata.c +++ b/ext/mysqlnd/mysqlnd_loaddata.c @@ -153,7 +153,6 @@ mysqlnd_handle_local_infile(MYSQLND_CONN_DATA * conn, const char * const filenam DBG_ENTER("mysqlnd_handle_local_infile"); if (!(conn->options->flags & CLIENT_LOCAL_FILES)) { - php_error_docref(NULL, E_WARNING, "LOAD DATA LOCAL INFILE forbidden"); SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, "LOAD DATA LOCAL INFILE is forbidden, check mysqli.allow_local_infile"); /* write empty packet to server */ From 29d0a62548dbb9c686480014a5514167ccc92517 Mon Sep 17 00:00:00 2001 From: Dharman Date: Mon, 21 Dec 2020 18:57:43 +0000 Subject: [PATCH 5/5] Add empty statement --- ext/mysqlnd/mysqlnd_auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/mysqlnd/mysqlnd_auth.c b/ext/mysqlnd/mysqlnd_auth.c index 1dbd1f9ebdddd..90adb2349b350 100644 --- a/ext/mysqlnd/mysqlnd_auth.c +++ b/ext/mysqlnd/mysqlnd_auth.c @@ -1272,7 +1272,7 @@ mysqlnd_caching_sha2_handle_server_response(struct st_mysqlnd_authentication_plu case 2: // The server tried to send a key, which we didn't expect // fall-through - default: + default: ; char * msg; mnd_sprintf(&msg, 0, "Unexpected server response while doing caching_sha2 auth: %i", result_packet.response_code); SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, msg);