Skip to content

Commit cfe5ee9

Browse files
committed
MDEV-22043 Special character leads to assertion in my_wc_to_printable_generic on 10.5.2 (debug)
The code did not take into account that: - U+005C (backslash) can occupy more than mbminlen characters (e.g. in sjis) - Some character sets do not have a code for U+005C (e.g. swe7) Adding a new function my_wc_to_printable into MY_CHARSET_HANDLER to cover all special cases easier.
1 parent c675886 commit cfe5ee9

25 files changed

+242
-18
lines changed

include/m_ctype.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ struct my_charset_handler_st
541541
my_ci_native_to_mb() rather than my_ci_wc_mb().
542542
*/
543543
my_charset_conv_wc_mb native_to_mb;
544+
my_charset_conv_wc_mb wc_to_printable;
544545
};
545546

546547
extern MY_CHARSET_HANDLER my_charset_8bit_handler;
@@ -660,6 +661,11 @@ struct charset_info_st
660661
return (cset->native_to_mb)(this, wc, s, e);
661662
}
662663

664+
int wc_to_printable(my_wc_t wc, uchar *s, uchar *e) const
665+
{
666+
return (cset->wc_to_printable)(this, wc, s, e);
667+
}
668+
663669
int ctype(int *to, const uchar *s, const uchar *e) const
664670
{
665671
return (cset->ctype)(this, to, s, e);
@@ -1249,9 +1255,6 @@ int my_wc_mb_bin(CHARSET_INFO *cs,my_wc_t wc, uchar *s, uchar *e);
12491255
int my_mb_ctype_8bit(CHARSET_INFO *,int *, const uchar *,const uchar *);
12501256
int my_mb_ctype_mb(CHARSET_INFO *,int *, const uchar *,const uchar *);
12511257

1252-
int my_wc_to_printable_generic(CHARSET_INFO *cs, my_wc_t wc,
1253-
uchar *s, uchar *e);
1254-
12551258
size_t my_scan_8bit(CHARSET_INFO *cs, const char *b, const char *e, int sq);
12561259

12571260
size_t my_snprintf_8bit(CHARSET_INFO *, char *to, size_t n,

mysql-test/main/ctype_filename.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,16 @@ SET NAMES utf8;
2121
SELECT @a:=CONVERT('aя' USING filename) AS `@a`, BINARY @a, REVERSE(@a), HEX(@a), HEX(REVERSE(@a));
2222
@a BINARY @a REVERSE(@a) HEX(@a) HEX(REVERSE(@a))
2323
aя a@r1 яa 61407231 40723161
24+
#
25+
# Start of 10.5 tests
26+
#
27+
#
28+
# MDEV-22043 Special character leads to assertion in my_wc_to_printable_generic on 10.5.2 (debug)
29+
#
30+
SET NAMES filename;
31+
EXECUTE IMMEDIATE _latin1 0x01;
32+
ERROR 42000: You@0020have@0020an@0020error@0020in@0020your@0020SQL@0020syntax@003b@0020check@0020the@0020manual@0020that@0020corresponds@0020to@0020your@0020MariaDB@0020server@0020version@0020for@0020the@0020right@0020syntax@0020to@0020use@0020near@0020@0027@005c0001@0027@0020at@0020line@00201
33+
SET NAMES utf8;
34+
#
35+
# End of 10.5 tests
36+
#

mysql-test/main/ctype_filename.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,22 @@ select convert(convert(',' using filename) using binary);
2727
--echo #
2828
SET NAMES utf8;
2929
SELECT @a:=CONVERT('aя' USING filename) AS `@a`, BINARY @a, REVERSE(@a), HEX(@a), HEX(REVERSE(@a));
30+
31+
32+
--echo #
33+
--echo # Start of 10.5 tests
34+
--echo #
35+
36+
--echo #
37+
--echo # MDEV-22043 Special character leads to assertion in my_wc_to_printable_generic on 10.5.2 (debug)
38+
--echo #
39+
40+
SET NAMES filename;
41+
--error ER_PARSE_ERROR
42+
EXECUTE IMMEDIATE _latin1 0x01;
43+
SET NAMES utf8;
44+
45+
46+
--echo #
47+
--echo # End of 10.5 tests
48+
--echo #

mysql-test/main/ctype_sjis.result

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19296,3 +19296,25 @@ SET DEFAULT_STORAGE_ENGINE=Default;
1929619296
#
1929719297
# End of 10.2 tests
1929819298
#
19299+
#
19300+
# Start of 10.5 tests
19301+
#
19302+
#
19303+
# MDEV-22043 Special character leads to assertion in my_wc_to_printable_generic on 10.5.2 (debug)
19304+
#
19305+
SET NAMES sjis;
19306+
SET @@CHARACTER_SET_CLIENT='cp1257';
19307+
(a(b 'т'));
19308+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'a(b '�_0143�_201A'))' at line 1
19309+
SET NAMES sjis;
19310+
SET @@CHARACTER_SET_CLIENT='cp1257';
19311+
'т';
19312+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''�_0143�_201A'' at line 1
19313+
SET NAMES sjis;
19314+
SET @@CHARACTER_SET_CLIENT='cp1257';
19315+
EXECUTE IMMEDIATE _cp1257 0xD182;
19316+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '�_0143�_201A' at line 1
19317+
SET NAMES sjis;
19318+
#
19319+
# End of 10.5 tests
19320+
#

mysql-test/main/ctype_sjis.test

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,33 @@ let $coll_pad='sjis_bin';
260260
--echo #
261261
--echo # End of 10.2 tests
262262
--echo #
263+
264+
--echo #
265+
--echo # Start of 10.5 tests
266+
--echo #
267+
268+
--echo #
269+
--echo # MDEV-22043 Special character leads to assertion in my_wc_to_printable_generic on 10.5.2 (debug)
270+
--echo #
271+
272+
SET NAMES sjis;
273+
SET @@CHARACTER_SET_CLIENT='cp1257';
274+
--error ER_PARSE_ERROR
275+
(a(b 'т'));
276+
277+
SET NAMES sjis;
278+
SET @@CHARACTER_SET_CLIENT='cp1257';
279+
--error ER_PARSE_ERROR
280+
'т';
281+
282+
SET NAMES sjis;
283+
SET @@CHARACTER_SET_CLIENT='cp1257';
284+
--error ER_PARSE_ERROR
285+
EXECUTE IMMEDIATE _cp1257 0xD182;
286+
287+
SET NAMES sjis;
288+
289+
290+
--echo #
291+
--echo # End of 10.5 tests
292+
--echo #

mysql-test/main/ctype_swe7.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3635,3 +3635,21 @@ SET DEFAULT_STORAGE_ENGINE=Default;
36353635
#
36363636
# End of 10.2 tests
36373637
#
3638+
#
3639+
# Start of 10.5 tests
3640+
#
3641+
#
3642+
# MDEV-22043 Special character leads to assertion in my_wc_to_printable_generic on 10.5.2 (debug)
3643+
#
3644+
SET NAMES swe7;
3645+
SELECT `T`;
3646+
ERROR HY000: Invalid swe7 character string: '.xEF.xBC.xB4'
3647+
SET NAMES swe7;
3648+
SELECT `龔`;
3649+
ERROR HY000: Invalid swe7 character string: '.xE9.xBE.x94'
3650+
SET NAMES swe7;
3651+
EXECUTE IMMEDIATE _swe7 0x01;
3652+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.0001' at line 1
3653+
#
3654+
# End of 10.5 tests
3655+
#

mysql-test/main/ctype_swe7.test

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,29 @@ let $coll_pad='swe7_bin';
3838
--echo #
3939
--echo # End of 10.2 tests
4040
--echo #
41+
42+
43+
--echo #
44+
--echo # Start of 10.5 tests
45+
--echo #
46+
47+
--echo #
48+
--echo # MDEV-22043 Special character leads to assertion in my_wc_to_printable_generic on 10.5.2 (debug)
49+
--echo #
50+
51+
SET NAMES swe7;
52+
--error ER_INVALID_CHARACTER_STRING
53+
SELECT `T`;
54+
55+
SET NAMES swe7;
56+
--error ER_INVALID_CHARACTER_STRING
57+
SELECT `龔`;
58+
59+
SET NAMES swe7;
60+
--error ER_PARSE_ERROR
61+
EXECUTE IMMEDIATE _swe7 0x01;
62+
63+
64+
--echo #
65+
--echo # End of 10.5 tests
66+
--echo #

sql/sql_error.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ extern "C" int my_wc_mb_utf8_null_terminated(CHARSET_INFO *cs,
850850
my_wc_t wc, uchar *r, uchar *e)
851851
{
852852
return wc == '\0' ?
853-
my_wc_to_printable_generic(cs, wc, r, e) :
853+
cs->wc_to_printable(wc, r, e) :
854854
my_charset_utf8mb3_handler.wc_mb(cs, wc, r, e);
855855
}
856856

@@ -951,7 +951,7 @@ size_t convert_error_message(char *to, size_t to_length, CHARSET_INFO *to_cs,
951951
to_cs= system_charset_info;
952952
uint32 cnv_length= my_convert_using_func(to, to_length,
953953
to_cs,
954-
my_wc_to_printable_generic,
954+
to_cs->cset->wc_to_printable,
955955
from, from_length,
956956
from_cs, from_cs->cset->mb_wc,
957957
errors);

sql/sql_string.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ bool Binary_string::copy_printable_hhhh(CHARSET_INFO *to_cs,
791791
if (bytes_needed >= UINT_MAX32 || alloc((size_t) bytes_needed))
792792
return true;
793793
str_length= my_convert_using_func(Ptr, Alloced_length, to_cs,
794-
my_wc_to_printable_generic,
794+
to_cs->cset->wc_to_printable,
795795
from, from_length,
796796
from_cs,
797797
from_cs->cset->mb_wc,

strings/ctype-big5.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6800,6 +6800,7 @@ static MY_CHARSET_HANDLER my_charset_big5_handler=
68006800
my_well_formed_char_length_big5,
68016801
my_copy_fix_mb,
68026802
my_native_to_mb_big5,
6803+
my_wc_to_printable_generic
68036804
};
68046805

68056806
struct charset_info_st my_charset_big5_chinese_ci=

0 commit comments

Comments
 (0)