Skip to content

Commit 29a39eb

Browse files
committed
Fixed handshake response charset. (php#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 php#13452 Closes php#13470
1 parent 6bcce68 commit 29a39eb

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.2.18
44

5+
- MySQLnd:
6+
. Fix GH-13452 (Fixed handshake response [mysqlnd]). (Saki Takamachi)
7+
58
- PDO:
69
. Fix various PDORow bugs. (Girgias)
710

ext/mysqlnd/mysqlnd_charset.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#ifndef MYSQLND_CHARSET_H
2020
#define MYSQLND_CHARSET_H
2121

22+
#define MYSQLND_UTF8_MB3_DEFAULT_ID 33
23+
#define MYSQLND_UTF8_MB4_DEFAULT_ID 45
24+
2225
PHPAPI zend_ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const charset, char * newstr,
2326
const char * escapestr, const size_t escapestr_len);
2427

ext/mysqlnd/mysqlnd_commands.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "mysqlnd_auth.h"
2323
#include "mysqlnd_wireprotocol.h"
2424
#include "mysqlnd_debug.h"
25+
#include "mysqlnd_charset.h"
2526

2627

2728
/* {{{ mysqlnd_command::set_option */
@@ -642,13 +643,12 @@ MYSQLND_METHOD(mysqlnd_command, handshake)(MYSQLND_CONN_DATA * const conn, const
642643
conn->protocol_version = greet_packet.protocol_version;
643644
conn->server_version = mnd_pestrdup(greet_packet.server_version, conn->persistent);
644645

645-
conn->greet_charset = mysqlnd_find_charset_nr(greet_packet.charset_no);
646-
if (!conn->greet_charset) {
647-
char * msg;
648-
mnd_sprintf(&msg, 0, "Server sent charset (%d) unknown to the client. Please, report to the developers", greet_packet.charset_no);
649-
SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, msg);
650-
mnd_sprintf_free(msg);
651-
goto err;
646+
const MYSQLND_CHARSET *read_charset = mysqlnd_find_charset_nr(greet_packet.charset_no);
647+
if (!read_charset) {
648+
greet_packet.charset_no = conn->m->get_server_version(conn) >= 50500 ? MYSQLND_UTF8_MB4_DEFAULT_ID : MYSQLND_UTF8_MB3_DEFAULT_ID;
649+
conn->greet_charset = mysqlnd_find_charset_nr(greet_packet.charset_no);
650+
} else {
651+
conn->greet_charset = read_charset;
652652
}
653653

654654
conn->server_capabilities = greet_packet.server_capabilities;

0 commit comments

Comments
 (0)