summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/main/disabled.def1
-rw-r--r--mysql-test/main/func_time.result15
-rw-r--r--mysql-test/main/func_time.test8
-rw-r--r--sql-common/my_time.c7
-rw-r--r--sql/sql_time.cc4
5 files changed, 32 insertions, 3 deletions
diff --git a/mysql-test/main/disabled.def b/mysql-test/main/disabled.def
index 5f8766c8aa3..e83ff00d10b 100644
--- a/mysql-test/main/disabled.def
+++ b/mysql-test/main/disabled.def
@@ -22,4 +22,3 @@ innodb_bug12902967 : broken upstream
file_contents : MDEV-6526 these files are not installed anymore
max_statement_time : cannot possibly work, depends on timing
connect-abstract : waiting for libmariadb update
-func_time : new tests fail on architectures with sizeof(long)=4. Barkov is working on fixing this.
diff --git a/mysql-test/main/func_time.result b/mysql-test/main/func_time.result
index c56d4da956a..8dcb7e36fcd 100644
--- a/mysql-test/main/func_time.result
+++ b/mysql-test/main/func_time.result
@@ -6098,3 +6098,18 @@ Message Truncated incorrect time value: '87648576:59:59.000001'
Level Warning
Code 1292
Message Truncated incorrect time value: '87648576:59:59.000001'
+#
+# MDEV-17400 The result of TIME('42949672965959-01') depends on architecture
+#
+SELECT TIME('42949672955959-01'), TIME('42949672965959-01');
+TIME('42949672955959-01') TIME('42949672965959-01')
+NULL NULL
+Warnings:
+Warning 1292 Truncated incorrect time value: '42949672955959-01'
+Warning 1292 Truncated incorrect time value: '42949672965959-01'
+SELECT TIME('18446744073709551615-01'), TIME('18446744073709551616-01');
+TIME('18446744073709551615-01') TIME('18446744073709551616-01')
+NULL NULL
+Warnings:
+Warning 1292 Truncated incorrect time value: '18446744073709551615-01'
+Warning 1292 Truncated incorrect time value: '18446744073709551616-01'
diff --git a/mysql-test/main/func_time.test b/mysql-test/main/func_time.test
index 2b031dbf3de..da00ff0eb45 100644
--- a/mysql-test/main/func_time.test
+++ b/mysql-test/main/func_time.test
@@ -3006,3 +3006,11 @@ SELECT
--horizontal_results
+
+
+--echo #
+--echo # MDEV-17400 The result of TIME('42949672965959-01') depends on architecture
+--echo #
+
+SELECT TIME('42949672955959-01'), TIME('42949672965959-01');
+SELECT TIME('18446744073709551615-01'), TIME('18446744073709551616-01');
diff --git a/sql-common/my_time.c b/sql-common/my_time.c
index 008b339e955..c2e5aeee44b 100644
--- a/sql-common/my_time.c
+++ b/sql-common/my_time.c
@@ -610,7 +610,11 @@ str_to_DDhhmmssff_internal(my_bool neg, const char *str, size_t length,
l_time->neg= neg;
/* Not a timestamp. Try to get this as a DAYS TO SECOND string */
for (value=0; str != end && my_isdigit(&my_charset_latin1,*str) ; str++)
+ {
value=value*10L + (long) (*str - '0');
+ if (value >= 42949672955959ULL) /* i.e. UINT_MAX32 : 59 : 59 */
+ goto err;
+ }
/* Skip all space after 'days' */
end_of_days= str;
@@ -629,6 +633,8 @@ str_to_DDhhmmssff_internal(my_bool neg, const char *str, size_t length,
my_isdigit(&my_charset_latin1, str[1]))
{
date[0]= 0; /* Assume we found hours */
+ if (value >= UINT_MAX32)
+ goto err;
date[1]= (ulong) value;
state=2;
found_hours=1;
@@ -638,6 +644,7 @@ str_to_DDhhmmssff_internal(my_bool neg, const char *str, size_t length,
{
/* String given as one number; assume HHMMSS format */
date[0]= 0;
+ DBUG_ASSERT(value <= ((ulonglong) UINT_MAX32) * 10000ULL);
date[1]= (ulong) (value/10000);
date[2]= (ulong) (value/100 % 100);
date[3]= (ulong) (value % 100);
diff --git a/sql/sql_time.cc b/sql/sql_time.cc
index 90803b48539..c3019668497 100644
--- a/sql/sql_time.cc
+++ b/sql/sql_time.cc
@@ -1117,10 +1117,10 @@ calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
}
microseconds= ((longlong)days * SECONDS_IN_24H +
- (longlong)(l_time1->hour*3600L +
+ (longlong)(l_time1->hour*3600LL +
l_time1->minute*60L +
l_time1->second) -
- l_sign*(longlong)(l_time2->hour*3600L +
+ l_sign*(longlong)(l_time2->hour*3600LL +
l_time2->minute*60L +
l_time2->second)) * 1000000LL +
(longlong)l_time1->second_part -