Skip to content

Commit 1fd0738

Browse files
author
Alexander Barkov
committed
MErging from mysql-5.5-security
2 parents aab66d4 + 324cb45 commit 1fd0738

9 files changed

+74
-6
lines changed

mysql-test/r/ctype_ujis.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,6 +2374,16 @@ hex(convert(_latin1 0xA4A2 using ujis)) hex(c2)
23742374
DROP PROCEDURE sp1;
23752375
DROP TABLE t1;
23762376
DROP TABLE t2;
2377+
#
2378+
# Bug#57257 Replace(ExtractValue(...)) causes MySQL crash
2379+
#
2380+
SET NAMES utf8;
2381+
SELECT CONVERT(REPLACE(EXPORT_SET('a','a','a','','a'),'00','') USING ujis);
2382+
CONVERT(REPLACE(EXPORT_SET('a','a','a','','a'),'00','') USING ujis)
2383+
2384+
Warnings:
2385+
Warning 1292 Truncated incorrect INTEGER value: 'a'
2386+
Warning 1292 Truncated incorrect INTEGER value: 'a'
23772387
set names default;
23782388
set character_set_database=default;
23792389
set character_set_server=default;

mysql-test/r/ctype_utf8.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4976,6 +4976,17 @@ maketime(`a`,`a`,`a`)
49764976
DROP TABLE t1;
49774977
SET sql_mode=default;
49784978
#
4979+
# Bug#57687 crash when reporting duplicate group_key error and utf8
4980+
# Make sure to modify this when Bug#58081 is fixed.
4981+
#
4982+
SET NAMES utf8;
4983+
CREATE TABLE t1 (a INT);
4984+
INSERT INTO t1 VALUES (0), (0), (1), (0), (0);
4985+
SELECT COUNT(*) FROM t1, t1 t2
4986+
GROUP BY INSERT('', t2.a, t1.a, (@@global.max_binlog_size));
4987+
ERROR 23000: Duplicate entry '107374182410737418241' for key 'group_key'
4988+
DROP TABLE t1;
4989+
#
49794990
# End of 5.5 tests
49804991
#
49814992
#

mysql-test/r/xml.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,4 +1093,17 @@ Warnings:
10931093
Warning 1525 Incorrect XML value: 'parse error at line 1 pos 23: unexpected END-OF-INPUT'
10941094
Warning 1525 Incorrect XML value: 'parse error at line 1 pos 23: unexpected END-OF-INPUT'
10951095
DROP TABLE t1;
1096+
#
1097+
# Bug#57257 Replace(ExtractValue(...)) causes MySQL crash
1098+
#
1099+
SET NAMES utf8;
1100+
SELECT REPLACE(EXTRACTVALUE('1', '/a'),'ds','');
1101+
REPLACE(EXTRACTVALUE('1', '/a'),'ds','')
1102+
1103+
#
1104+
# Bug #57820 extractvalue crashes
1105+
#
1106+
SELECT AVG(DISTINCT EXTRACTVALUE((''),('$@k')));
1107+
AVG(DISTINCT EXTRACTVALUE((''),('$@k')))
1108+
NULL
10961109
End of 5.1 tests

mysql-test/t/ctype_ujis.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,13 @@ DROP PROCEDURE sp1;
12091209
DROP TABLE t1;
12101210
DROP TABLE t2;
12111211

1212+
--echo #
1213+
--echo # Bug#57257 Replace(ExtractValue(...)) causes MySQL crash
1214+
--echo #
1215+
SET NAMES utf8;
1216+
SELECT CONVERT(REPLACE(EXPORT_SET('a','a','a','','a'),'00','') USING ujis);
1217+
1218+
12121219
set names default;
12131220
set character_set_database=default;
12141221
set character_set_server=default;

mysql-test/t/ctype_utf8.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,18 @@ DROP TABLE t1, t2;
15491549
SET NAMES utf8;
15501550
--source include/ctype_numconv.inc
15511551

1552+
--echo #
1553+
--echo # Bug#57687 crash when reporting duplicate group_key error and utf8
1554+
--echo # Make sure to modify this when Bug#58081 is fixed.
1555+
--echo #
1556+
SET NAMES utf8;
1557+
CREATE TABLE t1 (a INT);
1558+
INSERT INTO t1 VALUES (0), (0), (1), (0), (0);
1559+
--error ER_DUP_ENTRY
1560+
SELECT COUNT(*) FROM t1, t1 t2
1561+
GROUP BY INSERT('', t2.a, t1.a, (@@global.max_binlog_size));
1562+
DROP TABLE t1;
1563+
15521564

15531565
--echo #
15541566
--echo # End of 5.5 tests

mysql-test/t/xml.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,4 +617,15 @@ FROM t1 ORDER BY t1.id;
617617

618618
DROP TABLE t1;
619619

620+
--echo #
621+
--echo # Bug#57257 Replace(ExtractValue(...)) causes MySQL crash
622+
--echo #
623+
SET NAMES utf8;
624+
SELECT REPLACE(EXTRACTVALUE('1', '/a'),'ds','');
625+
626+
--echo #
627+
--echo # Bug #57820 extractvalue crashes
628+
--echo #
629+
SELECT AVG(DISTINCT EXTRACTVALUE((''),('$@k')));
630+
620631
--echo End of 5.1 tests

sql/item_strfunc.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,9 +1080,15 @@ String *Item_func_replace::val_str(String *str)
10801080
search=res2->ptr();
10811081
search_end=search+from_length;
10821082
redo:
1083+
DBUG_ASSERT(res->ptr() || !offset);
10831084
ptr=res->ptr()+offset;
10841085
strend=res->ptr()+res->length();
1085-
end=strend-from_length+1;
1086+
/*
1087+
In some cases val_str() can return empty string
1088+
with ptr() == NULL and length() == 0.
1089+
Let's check strend to avoid overflow.
1090+
*/
1091+
end= strend ? strend - from_length + 1 : NULL;
10861092
while (ptr < end)
10871093
{
10881094
if (*ptr == *search)

sql/item_xmlfunc.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,12 +2798,12 @@ String *Item_func_xml_extractvalue::val_str(String *str)
27982798
null_value= 0;
27992799
if (!nodeset_func ||
28002800
!(res= args[0]->val_str(str)) ||
2801-
!parse_xml(res, &pxml))
2801+
!parse_xml(res, &pxml) ||
2802+
!(res= nodeset_func->val_str(&tmp_value)))
28022803
{
28032804
null_value= 1;
28042805
return 0;
28052806
}
2806-
res= nodeset_func->val_str(&tmp_value);
28072807
return res;
28082808
}
28092809

sql/key.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,7 @@ void key_unpack(String *to,TABLE *table,uint idx)
364364
while (tmp_end > tmp.ptr() && !*--tmp_end) ;
365365
tmp.length(tmp_end - tmp.ptr() + 1);
366366
}
367-
if (cs->mbmaxlen > 1 &&
368-
table->field[key_part->fieldnr - 1]->field_length !=
369-
key_part->length)
367+
if (cs->mbmaxlen > 1 && (key_part->key_part_flag & HA_PART_KEY_SEG))
370368
{
371369
/*
372370
Prefix key, multi-byte charset.

0 commit comments

Comments
 (0)