Skip to content

Commit d1f42fc

Browse files
abarkovsanja-byelkin
authored andcommitted
MDEV-21589 AddressSanitizer: memcpy-param-overlap in Static_binary_string::q_append or String::append
Item_func_concat_ws::val_str(): - collects the result into the string "str" passed as a parameter. - calls val_str(&tmp_buffer) to get arguments. At some point due to heuristic it decides to swap the buffers: - collect the result into &tmp_buffer - call val_str(str) to get arguments Item_func_password::val_str_ascii() returns a String pointing to its member tmp_value[SCRAMBLED_PASSWORD_CHAR_LENGTH+1]. As a result, it's possible that both str and tmp_buffer in Item_func_concat_ws::val_str() point to Item_func_password::tmp_value. Then, memcmp() called on overlapping memory fragrments. Fixing Item_func_password::val_str_ascii() to use Item::copy() instead of Item::set().
1 parent 54c1031 commit d1f42fc

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

mysql-test/main/func_concat.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,20 @@ SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT MAKE_SET(3,t,t) t2 FROM t1) sub;
287287
c2
288288
abcdefghi,abcdefghi-abcdefghi,abcdefghi
289289
DROP TABLE t1;
290+
# Start of 10.5 tests
291+
#
292+
# MDEV-13120 Wrong results with MAKE_SET() and subquery
293+
#
294+
CREATE TABLE t1 (a DATE, b DATETIME, c VARCHAR(8));
295+
INSERT INTO t1 VALUES
296+
('1996-03-06','1985-11-16 08:00:46','foo'),
297+
('2028-08-26','1900-01-01 00:00:00','bar'),
298+
('1973-05-04','1900-01-01 00:00:00','qux');
299+
SELECT CONCAT_WS(' ', a, b, PASSWORD(c)) AS f FROM t1 GROUP BY f WITH ROLLUP;
300+
f
301+
1973-05-04 1900-01-01 00:00:00 *6D720C5AAB5096E70AA751206B45B484E5E0121F
302+
1996-03-06 1985-11-16 08:00:46 *F3A2A51A9B0F2BE2468926B4132313728C250DBF
303+
2028-08-26 1900-01-01 00:00:00 *E8D46CE25265E545D225A8A6F1BAF642FEBEE5CB
304+
NULL
305+
DROP TABLE t1;
306+
# End of 10.5 tests

mysql-test/main/func_concat.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,19 @@ CREATE TABLE t1 (t VARCHAR(10) CHARSET latin1);
265265
INSERT INTO t1 VALUES('abcdefghi');
266266
SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT MAKE_SET(3,t,t) t2 FROM t1) sub;
267267
DROP TABLE t1;
268+
269+
--echo # Start of 10.5 tests
270+
271+
--echo #
272+
--echo # MDEV-13120 Wrong results with MAKE_SET() and subquery
273+
--echo #
274+
275+
CREATE TABLE t1 (a DATE, b DATETIME, c VARCHAR(8));
276+
INSERT INTO t1 VALUES
277+
('1996-03-06','1985-11-16 08:00:46','foo'),
278+
('2028-08-26','1900-01-01 00:00:00','bar'),
279+
('1973-05-04','1900-01-01 00:00:00','qux');
280+
SELECT CONCAT_WS(' ', a, b, PASSWORD(c)) AS f FROM t1 GROUP BY f WITH ROLLUP;
281+
DROP TABLE t1;
282+
283+
--echo # End of 10.5 tests

sql/item_strfunc.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,15 +2241,15 @@ String *Item_func_password::val_str_ascii(String *str)
22412241
if (args[0]->null_value || res->length() == 0)
22422242
return make_empty_result(str);
22432243
my_make_scrambled_password(tmp_value, res->ptr(), res->length());
2244-
str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH, &my_charset_latin1);
2244+
str->copy(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH, &my_charset_latin1);
22452245
break;
22462246
case OLD:
22472247
if ((null_value=args[0]->null_value))
22482248
return 0;
22492249
if (res->length() == 0)
22502250
return make_empty_result(str);
22512251
my_make_scrambled_password_323(tmp_value, res->ptr(), res->length());
2252-
str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH_323, &my_charset_latin1);
2252+
str->copy(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH_323, &my_charset_latin1);
22532253
break;
22542254
default:
22552255
DBUG_ASSERT(0);

0 commit comments

Comments
 (0)