Commit e0f75b1b authored by Alexander Barkov's avatar Alexander Barkov

MDEV-5870 Assertion `ltime->neg == 0' fails with COALESCE, ADDDATE, MAKEDATE

A huge number in the "day" part of an interval made the code to return
a negative date erroneously. Adding a test to return an error on a too
large "day" value.
parent 887a210f
......@@ -2481,3 +2481,16 @@ CAST(ADDTIME(CASE WHEN 0 THEN a ELSE b END,0) AS CHAR)
2001-02-03 00:20:12
DROP TABLE t1;
SET timestamp=DEFAULT;
#
# MDEV-5870 Assertion `ltime->neg == 0' fails with COALESCE, ADDDATE, MAKEDATE
#
CREATE TABLE t1 (dt DATETIME);
INSERT INTO t1 VALUES ('2003-05-13 19:36:05'), ('2012-12-12 09:20:06');
SELECT COALESCE(ADDDATE(MAKEDATE(2011,121), dt), '2006-09-12' ) FROM t1;
COALESCE(ADDDATE(MAKEDATE(2011,121), dt), '2006-09-12' )
2006-09-12
2006-09-12
Warnings:
Warning 1441 Datetime function: datetime field overflow
Warning 1441 Datetime function: datetime field overflow
DROP TABLE t1;
......@@ -1511,3 +1511,12 @@ SELECT CAST(ADDTIME(COALESCE(a,b),0) AS CHAR) FROM t1;
SELECT CAST(ADDTIME(CASE WHEN 0 THEN a ELSE b END,0) AS CHAR) FROM t1;
DROP TABLE t1;
SET timestamp=DEFAULT;
--echo #
--echo # MDEV-5870 Assertion `ltime->neg == 0' fails with COALESCE, ADDDATE, MAKEDATE
--echo #
CREATE TABLE t1 (dt DATETIME);
INSERT INTO t1 VALUES ('2003-05-13 19:36:05'), ('2012-12-12 09:20:06');
SELECT COALESCE(ADDDATE(MAKEDATE(2011,121), dt), '2006-09-12' ) FROM t1;
DROP TABLE t1;
......@@ -921,6 +921,9 @@ bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type,
my_bool neg= 0;
enum enum_mysql_timestamp_type time_type= ltime->time_type;
if ((ulong) interval.day > MAX_DAY_NUMBER)
goto invalid_date;
if (time_type != MYSQL_TIMESTAMP_TIME)
ltime->day+= calc_daynr(ltime->year, ltime->month, 1) - 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment