Skip to content

Commit

Permalink
MDEV-21619 Server crash or assertion failures in my_datetime_to_str
Browse files Browse the repository at this point in the history
Item_cache_datetime::decimals was always copied from example->decimals
without limiting to 6 (maximum possible fractional digits), so
val_str() later crashed on asserts inside my_time_to_str() and
my_datetime_to_str().
  • Loading branch information
abarkov committed Jun 11, 2020
1 parent 1bcc5cd commit e835881
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mysql-test/r/type_date.result
Original file line number Diff line number Diff line change
Expand Up @@ -914,3 +914,21 @@ DROP TABLE t1;
#
# End of 10.1 tests
#
#
# Start of 10.2 tests
#
#
# MDEV-21619 Server crash or assertion failures in my_datetime_to_str
#
CREATE TABLE t1 (f DATE, KEY(f));
INSERT INTO t1 VALUES ('2020-01-01'),('2020-01-02');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1995.0000000 BETWEEN f AND '2012-12-12';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 index f f 4 NULL 2 50.00 Using where; Using index
Warnings:
Warning 1292 Incorrect datetime value: '1995.0000000'
Note 1003 select `test`.`t1`.`f` AS `f` from `test`.`t1` where '0000-00-00' between `test`.`t1`.`f` and <cache>('2012-12-12')
DROP TABLE t1;
#
# End of 10.2 tests
#
12 changes: 12 additions & 0 deletions mysql-test/r/type_datetime.result
Original file line number Diff line number Diff line change
Expand Up @@ -1330,5 +1330,17 @@ a
2000-10-00 00:00:00
DROP TABLE t1;
#
# MDEV-21619 Server crash or assertion failures in my_datetime_to_str
#
CREATE TABLE t1 (f DATETIME, KEY(f));
INSERT INTO t1 VALUES ('2020-01-01 00:00:00'),('2020-01-02 00:00:00');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1995.0000000 BETWEEN f AND '2012-12-12';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 index f f 6 NULL 2 50.00 Using where; Using index
Warnings:
Warning 1292 Incorrect datetime value: '1995.0000000'
Note 1003 select `test`.`t1`.`f` AS `f` from `test`.`t1` where '0000-00-00 00:00:00.000000' between `test`.`t1`.`f` and <cache>('2012-12-12')
DROP TABLE t1;
#
# End of 10.2 tests
#
12 changes: 12 additions & 0 deletions mysql-test/r/type_time.result
Original file line number Diff line number Diff line change
Expand Up @@ -1356,5 +1356,17 @@ CAST(f1() AS TIME)
00:00:00
DROP FUNCTION f1;
#
# MDEV-21619 Server crash or assertion failures in my_datetime_to_str
#
CREATE TABLE t1 (f TIME, KEY(f));
INSERT INTO t1 VALUES ('10:10:10'),('20:20:20');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1995.0000000 BETWEEN f AND '23:59:59';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 index f f 4 NULL 2 100.00 Using where; Using index
Warnings:
Warning 1292 Incorrect datetime value: '1995.0000000'
Note 1003 select `test`.`t1`.`f` AS `f` from `test`.`t1` where '00:00:00.000000' between `test`.`t1`.`f` and <cache>('23:59:59')
DROP TABLE t1;
#
# End of 10.2 tests
#
18 changes: 18 additions & 0 deletions mysql-test/t/type_date.test
Original file line number Diff line number Diff line change
Expand Up @@ -627,3 +627,21 @@ DROP TABLE t1;
--echo #
--echo # End of 10.1 tests
--echo #

--echo #
--echo # Start of 10.2 tests
--echo #

--echo #
--echo # MDEV-21619 Server crash or assertion failures in my_datetime_to_str
--echo #

CREATE TABLE t1 (f DATE, KEY(f));
INSERT INTO t1 VALUES ('2020-01-01'),('2020-01-02');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1995.0000000 BETWEEN f AND '2012-12-12';
DROP TABLE t1;


--echo #
--echo # End of 10.2 tests
--echo #
9 changes: 9 additions & 0 deletions mysql-test/t/type_datetime.test
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,15 @@ ALTER TABLE t1 MODIFY a DATETIME;
SELECT * FROM t1;
DROP TABLE t1;

--echo #
--echo # MDEV-21619 Server crash or assertion failures in my_datetime_to_str
--echo #

CREATE TABLE t1 (f DATETIME, KEY(f));
INSERT INTO t1 VALUES ('2020-01-01 00:00:00'),('2020-01-02 00:00:00');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1995.0000000 BETWEEN f AND '2012-12-12';
DROP TABLE t1;


--echo #
--echo # End of 10.2 tests
Expand Down
9 changes: 9 additions & 0 deletions mysql-test/t/type_time.test
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,15 @@ SELECT CAST(f1() AS TIME);
DROP FUNCTION f1;


--echo #
--echo # MDEV-21619 Server crash or assertion failures in my_datetime_to_str
--echo #

CREATE TABLE t1 (f TIME, KEY(f));
INSERT INTO t1 VALUES ('10:10:10'),('20:20:20');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1995.0000000 BETWEEN f AND '23:59:59';
DROP TABLE t1;

--echo #
--echo # End of 10.2 tests
--echo #
7 changes: 7 additions & 0 deletions sql/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -5803,6 +5803,13 @@ class Item_cache_temporal: public Item_cache_int
bool cache_value();
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
int save_in_field(Field *field, bool no_conversions);
bool setup(THD *thd, Item *item)
{
if (Item_cache_int::setup(thd, item))
return true;
set_if_smaller(decimals, TIME_SECOND_PART_DIGITS);
return false;
}
Item_result cmp_type() const { return TIME_RESULT; }
void store_packed(longlong val_arg, Item *example);
/*
Expand Down

0 comments on commit e835881

Please sign in to comment.