diff options
author | Alexander Barkov <bar@mariadb.com> | 2020-06-11 15:33:16 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2020-06-11 15:33:16 +0400 |
commit | e835881c474ec1c43ab3c24a9d4a6e2615fb3398 (patch) | |
tree | 3446a82a15c1ecbe0349ff0e4facb695b8a792b1 | |
parent | 1bcc5cd9b6d29d3b625019fb66ad185cd7fbd546 (diff) | |
download | mariadb-git-e835881c474ec1c43ab3c24a9d4a6e2615fb3398.tar.gz |
MDEV-21619 Server crash or assertion failures in my_datetime_to_str
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().
-rw-r--r-- | mysql-test/r/type_date.result | 18 | ||||
-rw-r--r-- | mysql-test/r/type_datetime.result | 12 | ||||
-rw-r--r-- | mysql-test/r/type_time.result | 12 | ||||
-rw-r--r-- | mysql-test/t/type_date.test | 18 | ||||
-rw-r--r-- | mysql-test/t/type_datetime.test | 9 | ||||
-rw-r--r-- | mysql-test/t/type_time.test | 9 | ||||
-rw-r--r-- | sql/item.h | 7 |
7 files changed, 85 insertions, 0 deletions
diff --git a/mysql-test/r/type_date.result b/mysql-test/r/type_date.result index 5429d8cd059..494a7047986 100644 --- a/mysql-test/r/type_date.result +++ b/mysql-test/r/type_date.result @@ -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 +# diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result index a52c7d46684..ce49f628341 100644 --- a/mysql-test/r/type_datetime.result +++ b/mysql-test/r/type_datetime.result @@ -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 # diff --git a/mysql-test/r/type_time.result b/mysql-test/r/type_time.result index 41361d7e20d..90d09ea595f 100644 --- a/mysql-test/r/type_time.result +++ b/mysql-test/r/type_time.result @@ -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 # diff --git a/mysql-test/t/type_date.test b/mysql-test/t/type_date.test index 7c78460c1b4..b1c8cb0063b 100644 --- a/mysql-test/t/type_date.test +++ b/mysql-test/t/type_date.test @@ -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 # diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test index d965dc79074..49ae8490761 100644 --- a/mysql-test/t/type_datetime.test +++ b/mysql-test/t/type_datetime.test @@ -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 diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test index c9c39e28ef0..9ef80cf28fb 100644 --- a/mysql-test/t/type_time.test +++ b/mysql-test/t/type_time.test @@ -815,5 +815,14 @@ 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 # diff --git a/sql/item.h b/sql/item.h index 6f009fe904b..7338c8be47b 100644 --- a/sql/item.h +++ b/sql/item.h @@ -5803,6 +5803,13 @@ public: 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); /* |