Skip to content

Commit a765cca

Browse files
author
Alexander Barkov
committed
MDEV-8067 correct fix for MySQL Bug # 19699237: UNINITIALIZED VARIABLE IN ITEM_FIELD::STR_RESULT
1 parent b37b52a commit a765cca

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

mysql-test/r/ctype_utf8.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5762,5 +5762,20 @@ DROP TABLE t1;
57625762
# End of ctype_utf8_ilseq.inc
57635763
#
57645764
#
5765+
# MDEV-8067 correct fix for MySQL Bug # 19699237: UNINITIALIZED VARIABLE IN ITEM_FIELD::STR_RESULT
5766+
#
5767+
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8);
5768+
CREATE TABLE t2 (a VARCHAR(10) CHARACTER SET latin1);
5769+
INSERT INTO t1 VALUES ('aaa');
5770+
INSERT INTO t2 VALUES ('aaa');
5771+
SELECT (SELECT CONCAT(a),1 FROM t1) <=> (SELECT CONCAT(a),1 FROM t2);
5772+
(SELECT CONCAT(a),1 FROM t1) <=> (SELECT CONCAT(a),1 FROM t2)
5773+
1
5774+
INSERT INTO t1 VALUES ('aaa');
5775+
INSERT INTO t2 VALUES ('aaa');
5776+
SELECT (SELECT CONCAT(a),1 FROM t1) <=> (SELECT CONCAT(a),1 FROM t2);
5777+
ERROR 21000: Subquery returns more than 1 row
5778+
DROP TABLE t1, t2;
5779+
#
57655780
# End of 5.5 tests
57665781
#

mysql-test/t/ctype_utf8.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,22 @@ SET NAMES utf8 COLLATE utf8_general_ci;
16161616
--let ENGINE=HEAP
16171617
--source include/ctype_utf8_ilseq.inc
16181618

1619+
--echo #
1620+
--echo # MDEV-8067 correct fix for MySQL Bug # 19699237: UNINITIALIZED VARIABLE IN ITEM_FIELD::STR_RESULT
1621+
--echo #
1622+
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8);
1623+
CREATE TABLE t2 (a VARCHAR(10) CHARACTER SET latin1);
1624+
INSERT INTO t1 VALUES ('aaa');
1625+
INSERT INTO t2 VALUES ('aaa');
1626+
SELECT (SELECT CONCAT(a),1 FROM t1) <=> (SELECT CONCAT(a),1 FROM t2);
1627+
INSERT INTO t1 VALUES ('aaa');
1628+
INSERT INTO t2 VALUES ('aaa');
1629+
# Running the below query crashed with two rows
1630+
--error ER_SUBQUERY_NO_1_ROW
1631+
SELECT (SELECT CONCAT(a),1 FROM t1) <=> (SELECT CONCAT(a),1 FROM t2);
1632+
DROP TABLE t1, t2;
1633+
1634+
16191635
--echo #
16201636
--echo # End of 5.5 tests
16211637
--echo #

sql/item.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,36 @@ Item *Item::safe_charset_converter(CHARSET_INFO *tocs)
11351135
}
11361136

11371137

1138+
/**
1139+
Some pieces of the code do not support changing of
1140+
Item_cache to other Item types.
1141+
1142+
Example:
1143+
Item_singlerow_subselect has "Item_cache **row".
1144+
Creating of Item_func_conv_charset followed by THD::change_item_tree()
1145+
should not change row[i] from Item_cache directly to Item_func_conv_charset, because Item_singlerow_subselect
1146+
because Item_singlerow_subselect later calls Item_cache-specific methods,
1147+
e.g. row[i]->store() and row[i]->cache_value().
1148+
1149+
Let's wrap Item_func_conv_charset to a new Item_cache,
1150+
so the Item_cache-specific methods can still be used for
1151+
Item_singlerow_subselect::row[i] safely.
1152+
1153+
TODO: we should eventually check all other use cases of change_item_tree().
1154+
Perhaps some more potentially dangerous substitution examples exist.
1155+
*/
1156+
Item *Item_cache::safe_charset_converter(CHARSET_INFO *tocs)
1157+
{
1158+
Item_func_conv_charset *conv= new Item_func_conv_charset(example, tocs, 1);
1159+
Item_cache *cache;
1160+
if (!conv || !conv->safe || !(cache= new Item_cache_str(conv)))
1161+
return NULL; // Safe conversion is not possible, or OEM
1162+
cache->setup(conv);
1163+
cache->fixed= false; // Make Item::fix_fields() happy
1164+
return cache;
1165+
}
1166+
1167+
11381168
/**
11391169
@details
11401170
Created mostly for mysql_prepare_table(). Important

sql/item.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4161,6 +4161,7 @@ class Item_cache: public Item_basic_constant
41614161
return TRUE;
41624162
return (this->*processor)(arg);
41634163
}
4164+
virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
41644165
};
41654166

41664167

0 commit comments

Comments
 (0)