Skip to content

Commit 059797e

Browse files
committed
MDEV-24901 SIGSEGV in fts_get_table_name, SIGSEGV in ib_vector_size, SIGSEGV in row_merge_fts_doc_tokenize, stack smashing
strmake() puts one extra 0x00 byte at the end of the string. The code in my_strnxfrm_tis620[_nopad] did not take this into account, so in the reported scenario the 0x00 byte was put outside of a stack variable, which made ASAN crash. This problem is already fixed in in MySQL: commit 19bd66fe43c41f0bde5f36bc6b455a46693069fb Author: bin.x.su@oracle.com <> Date: Fri Apr 4 11:35:27 2014 +0800 But the fix does not seem to be correct, as it breaks when finds a zero byte in the source string. Using memcpy() instead of strmake(). - Unlike strmake(), memcpy() it does not write beyond the destination size passed. - Unlike the MySQL fix, memcpy() does not break on the first 0x00 byte found in the source string.
1 parent 42ae765 commit 059797e

File tree

5 files changed

+81
-4
lines changed

5 files changed

+81
-4
lines changed

mysql-test/r/ctype_tis620.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4421,5 +4421,14 @@ DROP TABLE t1;
44214421
#
44224422
SET STORAGE_ENGINE=Default;
44234423
#
4424+
# MDEV-24901 SIGSEGV in fts_get_table_name, SIGSEGV in ib_vector_size, SIGSEGV in row_merge_fts_doc_tokenize, stack smashing
4425+
#
4426+
SELECT HEX(WEIGHT_STRING(_tis620 'a\0b'));
4427+
HEX(WEIGHT_STRING(_tis620 'a\0b'))
4428+
610062
4429+
SELECT HEX(WEIGHT_STRING(_tis620 'a\0b' COLLATE tis620_thai_nopad_ci));
4430+
HEX(WEIGHT_STRING(_tis620 'a\0b' COLLATE tis620_thai_nopad_ci))
4431+
610062
4432+
#
44244433
# End of 10.2 tests
44254434
#
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
SET STORAGE_ENGINE=InnoDB;
2+
#
3+
# Start of 10.2 tests
4+
#
5+
#
6+
# MDEV-24901 SIGSEGV in fts_get_table_name, SIGSEGV in ib_vector_size, SIGSEGV in row_merge_fts_doc_tokenize, stack smashing Export
7+
#
8+
CREATE TABLE t1(c TEXT CHARACTER SET tis620);
9+
SHOW CREATE TABLE t1;
10+
Table Create Table
11+
t1 CREATE TABLE `t1` (
12+
`c` text CHARACTER SET tis620 DEFAULT NULL
13+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
14+
INSERT INTO t1 VALUES('100');
15+
ALTER TABLE t1 ADD FULLTEXT INDEX(c), ALGORITHM=INPLACE;
16+
Warnings:
17+
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
18+
DROP TABLE t1;
19+
CREATE TABLE t1(c TEXT CHARACTER SET tis620 COLLATE tis620_thai_nopad_ci);
20+
SHOW CREATE TABLE t1;
21+
Table Create Table
22+
t1 CREATE TABLE `t1` (
23+
`c` text CHARACTER SET tis620 COLLATE tis620_thai_nopad_ci DEFAULT NULL
24+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
25+
INSERT INTO t1 VALUES('100');
26+
ALTER TABLE t1 ADD FULLTEXT INDEX(c), ALGORITHM=INPLACE;
27+
Warnings:
28+
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
29+
DROP TABLE t1;
30+
#
31+
# End of 10.2 tests
32+
#
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--source include/have_innodb.inc
2+
--source include/have_tis620.inc
3+
4+
SET STORAGE_ENGINE=InnoDB;
5+
6+
--echo #
7+
--echo # Start of 10.2 tests
8+
--echo #
9+
10+
--echo #
11+
--echo # MDEV-24901 SIGSEGV in fts_get_table_name, SIGSEGV in ib_vector_size, SIGSEGV in row_merge_fts_doc_tokenize, stack smashing Export
12+
--echo #
13+
14+
CREATE TABLE t1(c TEXT CHARACTER SET tis620);
15+
SHOW CREATE TABLE t1;
16+
INSERT INTO t1 VALUES('100');
17+
ALTER TABLE t1 ADD FULLTEXT INDEX(c), ALGORITHM=INPLACE;
18+
DROP TABLE t1;
19+
20+
CREATE TABLE t1(c TEXT CHARACTER SET tis620 COLLATE tis620_thai_nopad_ci);
21+
SHOW CREATE TABLE t1;
22+
INSERT INTO t1 VALUES('100');
23+
ALTER TABLE t1 ADD FULLTEXT INDEX(c), ALGORITHM=INPLACE;
24+
DROP TABLE t1;
25+
26+
27+
--echo #
28+
--echo # End of 10.2 tests
29+
--echo #

mysql-test/t/ctype_tis620.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ let $coll='tis620_nopad_bin';
209209
let $coll_pad='tis620_bin';
210210
--source include/ctype_pad_all_engines.inc
211211

212+
--echo #
213+
--echo # MDEV-24901 SIGSEGV in fts_get_table_name, SIGSEGV in ib_vector_size, SIGSEGV in row_merge_fts_doc_tokenize, stack smashing
214+
--echo #
215+
216+
SELECT HEX(WEIGHT_STRING(_tis620 'a\0b'));
217+
SELECT HEX(WEIGHT_STRING(_tis620 'a\0b' COLLATE tis620_thai_nopad_ci));
218+
212219
--echo #
213220
--echo # End of 10.2 tests
214221
--echo #

strings/ctype-tis620.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,8 @@ my_strnxfrm_tis620(CHARSET_INFO *cs,
605605
const uchar *src, size_t srclen, uint flags)
606606
{
607607
size_t len, dstlen0= dstlen;
608-
len= (uint) (strmake((char*) dst, (char*) src, MY_MIN(dstlen, srclen)) -
609-
(char*) dst);
608+
len= MY_MIN(dstlen, srclen);
609+
memcpy(dst, src, len);
610610
len= thai2sortable(dst, len);
611611
set_if_smaller(dstlen, nweights);
612612
set_if_smaller(len, dstlen);
@@ -628,8 +628,8 @@ my_strnxfrm_tis620_nopad(CHARSET_INFO *cs,
628628
const uchar *src, size_t srclen, uint flags)
629629
{
630630
size_t len, dstlen0= dstlen;
631-
len= (uint) (strmake((char*) dst, (char*) src, MY_MIN(dstlen, srclen)) -
632-
(char*) dst);
631+
len= MY_MIN(dstlen, srclen);
632+
memcpy(dst, src, len);
633633
len= thai2sortable(dst, len);
634634
set_if_smaller(dstlen, nweights);
635635
set_if_smaller(len, dstlen);

0 commit comments

Comments
 (0)