[Commits] Rev 4078: MDEV-5870 Assertion `ltime->neg == 0' fails with COALESCE, ADDDATE, MAKEDATE in lp:~maria-captains/maria/10.0

Alexander Barkov bar at mariadb.org
Sun Mar 23 12:29:07 EET 2014


At lp:~maria-captains/maria/10.0

------------------------------------------------------------
revno: 4078
revision-id: bar at mariadb.org-20140323102244-90xhho5gpg7i7n6w
parent: igor at askmonty.org-20140322194439-2b3ygjmgdm5q379c
committer: Alexander Barkov <bar at mariadb.org>
branch nick: maria-10.0
timestamp: Sun 2014-03-23 14:22:44 +0400
message:
  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.
=== modified file 'mysql-test/r/func_time.result'
--- a/mysql-test/r/func_time.result	2014-03-06 20:21:25 +0000
+++ b/mysql-test/r/func_time.result	2014-03-23 10:22:44 +0000
@@ -2481,3 +2481,16 @@ CAST(ADDTIME(CASE WHEN 0 THEN a ELSE b E
 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;

=== modified file 'mysql-test/t/func_time.test'
--- a/mysql-test/t/func_time.test	2014-03-06 20:21:25 +0000
+++ b/mysql-test/t/func_time.test	2014-03-23 10:22:44 +0000
@@ -1511,3 +1511,12 @@ SELECT CAST(ADDTIME(COALESCE(a,b),0) AS
 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;

=== modified file 'sql/sql_time.cc'
--- a/sql/sql_time.cc	2014-03-07 20:05:28 +0000
+++ b/sql/sql_time.cc	2014-03-23 10:22:44 +0000
@@ -921,6 +921,9 @@ bool date_add_interval(MYSQL_TIME *ltime
     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;
 



More information about the commits mailing list