From 25f365f610ad00bcf9bccae98a62158332093f1c Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Tue, 15 Dec 2009 23:20:53 +0300 Subject: [PATCH] Backporting patch for Bug#47756 from mysql-next-mr-bugfixing into mysql-trunk-bugfixing. NOTE: the "utf8_phone_ci" collation does not exist in mysql-trunk yet, so another collation with 2-byte collation ID is used: "utf8_test_ci". This patch will be null-merged to mysql-next-mr-bugfixing. Original revision: ------------------------------------------------------------ revision-id: bar@mysql.com-20091207121153-hs3bqbmr0719ws21 committer: Alexander Barkov branch nick: mysql-next-mr.b47756 timestamp: Mon 2009-12-07 16:11:53 +0400 message: Bug#47756 Setting 2byte collation ID with 'set names' crashes the server The problem is not actually related to 2byte collation IDs. The same crash happens if you change the collation ID in mysql-test/str_data/Index.xml to a value smaller than 256. Crash happened in SQL parser, because the "ident_map" and "state_map" arrays were not initialized in loadable utf8 collations. Fix: adding proper initialization of the "ident_map" and "state_map" members for loadable utf8 collations. ------------------------------------------------------------ --- mysql-test/r/ctype_ldml.result | 5 +++++ mysql-test/t/ctype_ldml.test | 8 ++++++++ mysys/charset.c | 3 +++ 3 files changed, 16 insertions(+) diff --git a/mysql-test/r/ctype_ldml.result b/mysql-test/r/ctype_ldml.result index 00da0db1735..a63dc91f305 100644 --- a/mysql-test/r/ctype_ldml.result +++ b/mysql-test/r/ctype_ldml.result @@ -369,3 +369,8 @@ s1 a b DROP TABLE t1; +SET NAMES utf8 COLLATE utf8_test_ci; +SHOW COLLATION LIKE 'utf8_test_ci'; +Collation Charset Id Default Compiled Sortlen +utf8_test_ci utf8 353 8 +SET NAMES utf8; diff --git a/mysql-test/t/ctype_ldml.test b/mysql-test/t/ctype_ldml.test index 0fcfd603aad..d134861cd46 100644 --- a/mysql-test/t/ctype_ldml.test +++ b/mysql-test/t/ctype_ldml.test @@ -125,3 +125,11 @@ CREATE TABLE t1 (s1 char(10) character set utf8 collate utf8_maxuserid_ci); INSERT INTO t1 VALUES ('a'),('b'); SELECT * FROM t1 WHERE s1='a' ORDER BY BINARY s1; DROP TABLE t1; + + +# +# Bug#47756 Setting 2byte collation ID with 'set names' crashes the server +# +SET NAMES utf8 COLLATE utf8_test_ci; +SHOW COLLATION LIKE 'utf8_test_ci'; +SET NAMES utf8; diff --git a/mysys/charset.c b/mysys/charset.c index 280b2ad6091..e216f665092 100644 --- a/mysys/charset.c +++ b/mysys/charset.c @@ -255,6 +255,9 @@ static int add_collation(CHARSET_INFO *cs) { #if defined (HAVE_CHARSET_utf8) && defined(HAVE_UCA_COLLATIONS) copy_uca_collation(newcs, &my_charset_utf8_unicode_ci); + newcs->ctype= my_charset_utf8_unicode_ci.ctype; + if (init_state_maps(newcs)) + return MY_XML_ERROR; #endif } else