From 6bcce681ef3e57777da05b7cf28801c61f27ea38 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Mon, 4 Mar 2024 21:50:37 +0900 Subject: [PATCH 1/4] [skip ci] Fixed NEWS --- NEWS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 2f32dd10f9f..a8afd0b7bde 100644 --- a/NEWS +++ b/NEWS @@ -15,7 +15,7 @@ PHP NEWS - Standard: . Fixed bug GH-11808 (Live filesystem modified by tests). (nielsdos) - . Fixed GH-13402: Added validation of `\n` in `$additional_headers` of `mail()` + . Fixed GH-13402 (Added validation of `\n` in $additional_headers of mail()). (SakiTakamachi) - XML: From 29a39eb782f8cf74642152e0e62b5ef6da78301d Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Mon, 4 Mar 2024 21:51:02 +0900 Subject: [PATCH 2/4] Fixed handshake response charset. (#13470) The character set ID included in the handshake data at the time of connection actually only includes the lower 8 bits of the ID, so if try to use this to specify a character set, the corresponding character set may not exist. In case of an invalid character set, the default character set is now used without an error. Fixes #13452 Closes #13470 --- NEWS | 3 +++ ext/mysqlnd/mysqlnd_charset.h | 3 +++ ext/mysqlnd/mysqlnd_commands.c | 14 +++++++------- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index a8afd0b7bde..c7be80af560 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,9 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.2.18 +- MySQLnd: + . Fix GH-13452 (Fixed handshake response [mysqlnd]). (Saki Takamachi) + - PDO: . Fix various PDORow bugs. (Girgias) diff --git a/ext/mysqlnd/mysqlnd_charset.h b/ext/mysqlnd/mysqlnd_charset.h index d7f8053dd86..a2b1e2f1483 100644 --- a/ext/mysqlnd/mysqlnd_charset.h +++ b/ext/mysqlnd/mysqlnd_charset.h @@ -19,6 +19,9 @@ #ifndef MYSQLND_CHARSET_H #define MYSQLND_CHARSET_H +#define MYSQLND_UTF8_MB3_DEFAULT_ID 33 +#define MYSQLND_UTF8_MB4_DEFAULT_ID 45 + PHPAPI zend_ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const charset, char * newstr, const char * escapestr, const size_t escapestr_len); diff --git a/ext/mysqlnd/mysqlnd_commands.c b/ext/mysqlnd/mysqlnd_commands.c index ae645608505..a0266597685 100644 --- a/ext/mysqlnd/mysqlnd_commands.c +++ b/ext/mysqlnd/mysqlnd_commands.c @@ -22,6 +22,7 @@ #include "mysqlnd_auth.h" #include "mysqlnd_wireprotocol.h" #include "mysqlnd_debug.h" +#include "mysqlnd_charset.h" /* {{{ mysqlnd_command::set_option */ @@ -642,13 +643,12 @@ MYSQLND_METHOD(mysqlnd_command, handshake)(MYSQLND_CONN_DATA * const conn, const conn->protocol_version = greet_packet.protocol_version; conn->server_version = mnd_pestrdup(greet_packet.server_version, conn->persistent); - conn->greet_charset = mysqlnd_find_charset_nr(greet_packet.charset_no); - if (!conn->greet_charset) { - 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; + const MYSQLND_CHARSET *read_charset = mysqlnd_find_charset_nr(greet_packet.charset_no); + if (!read_charset) { + greet_packet.charset_no = conn->m->get_server_version(conn) >= 50500 ? MYSQLND_UTF8_MB4_DEFAULT_ID : MYSQLND_UTF8_MB3_DEFAULT_ID; + conn->greet_charset = mysqlnd_find_charset_nr(greet_packet.charset_no); + } else { + conn->greet_charset = read_charset; } conn->server_capabilities = greet_packet.server_capabilities; From 7466f9c99c4864fc17900f434b298c1deac9cb58 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Mon, 4 Mar 2024 21:51:02 +0900 Subject: [PATCH 3/4] Fixed handshake response charset. (#13470) The character set ID included in the handshake data at the time of connection actually only includes the lower 8 bits of the ID, so if try to use this to specify a character set, the corresponding character set may not exist. In case of an invalid character set, the default character set is now used without an error. Fixes #13452 Closes #13470 --- ext/mysqlnd/mysqlnd_charset.h | 3 +++ ext/mysqlnd/mysqlnd_commands.c | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ext/mysqlnd/mysqlnd_charset.h b/ext/mysqlnd/mysqlnd_charset.h index d7f8053dd86..a2b1e2f1483 100644 --- a/ext/mysqlnd/mysqlnd_charset.h +++ b/ext/mysqlnd/mysqlnd_charset.h @@ -19,6 +19,9 @@ #ifndef MYSQLND_CHARSET_H #define MYSQLND_CHARSET_H +#define MYSQLND_UTF8_MB3_DEFAULT_ID 33 +#define MYSQLND_UTF8_MB4_DEFAULT_ID 45 + PHPAPI zend_ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const charset, char * newstr, const char * escapestr, const size_t escapestr_len); diff --git a/ext/mysqlnd/mysqlnd_commands.c b/ext/mysqlnd/mysqlnd_commands.c index ba214e5ff77..27a5f13a307 100644 --- a/ext/mysqlnd/mysqlnd_commands.c +++ b/ext/mysqlnd/mysqlnd_commands.c @@ -22,6 +22,7 @@ #include "mysqlnd_auth.h" #include "mysqlnd_wireprotocol.h" #include "mysqlnd_debug.h" +#include "mysqlnd_charset.h" /* {{{ mysqlnd_command::set_option */ @@ -613,13 +614,12 @@ MYSQLND_METHOD(mysqlnd_command, handshake)(MYSQLND_CONN_DATA * const conn, const conn->protocol_version = greet_packet.protocol_version; conn->server_version = mnd_pestrdup(greet_packet.server_version, conn->persistent); - conn->greet_charset = mysqlnd_find_charset_nr(greet_packet.charset_no); - if (!conn->greet_charset) { - 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; + const MYSQLND_CHARSET *read_charset = mysqlnd_find_charset_nr(greet_packet.charset_no); + if (!read_charset) { + greet_packet.charset_no = conn->m->get_server_version(conn) >= 50500 ? MYSQLND_UTF8_MB4_DEFAULT_ID : MYSQLND_UTF8_MB3_DEFAULT_ID; + conn->greet_charset = mysqlnd_find_charset_nr(greet_packet.charset_no); + } else { + conn->greet_charset = read_charset; } conn->server_capabilities = greet_packet.server_capabilities; From 72779e6d64139d723c19857694a094c37e7a2e36 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Mon, 4 Mar 2024 21:53:09 +0900 Subject: [PATCH 4/4] NEWS --- NEWS | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS b/NEWS index 2b46b639a9b..1c9d7e4f511 100644 --- a/NEWS +++ b/NEWS @@ -2,12 +2,17 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.3.5 +- MySQLnd: + . Fix GH-13452 (Fixed handshake response [mysqlnd]). (Saki Takamachi) + - Random: . Fixed bug GH-13544 (Pre-PHP 8.2 compatibility for mt_srand with unknown modes). (timwolla) - Standard: . Fixed bug GH-11808 (Live filesystem modified by tests). (nielsdos) + . Fixed GH-13402 (Added validation of `\n` in $additional_headers of mail()). + (SakiTakamachi) 14 Mar 2024, PHP 8.3.4