diff options
author | Georgi Kodinov <Georgi.Kodinov@Oracle.com> | 2011-02-02 19:05:28 +0200 |
---|---|---|
committer | Georgi Kodinov <Georgi.Kodinov@Oracle.com> | 2011-02-02 19:05:28 +0200 |
commit | 72ae1d65dd62f1e2cc308549a84a46feadd158f4 (patch) | |
tree | 4635605ae0572f713774190b2fe771d0df3a1f96 | |
parent | e805a0fd9de24cf1a9a6fb7bd10a336dbcd46fe9 (diff) | |
parent | a70c34bf0f34703fd330f8cb828e48b303c5296a (diff) | |
download | mariadb-git-72ae1d65dd62f1e2cc308549a84a46feadd158f4.tar.gz |
merge to 5.1.
-rw-r--r-- | configure.in | 9 | ||||
-rw-r--r-- | include/config-win.h | 5 | ||||
-rw-r--r-- | include/my_time.h | 13 | ||||
-rw-r--r-- | mysql-test/r/func_time.result | 17 | ||||
-rw-r--r-- | mysql-test/t/func_time.test | 19 | ||||
-rw-r--r-- | mysql-test/t/variables.test | 2 | ||||
-rw-r--r-- | sql-common/my_time.c | 2 | ||||
-rw-r--r-- | sql/mysqld.cc | 13 | ||||
-rw-r--r-- | sql/set_var.cc | 12 | ||||
-rw-r--r-- | sql/sql_class.h | 2 |
10 files changed, 79 insertions, 15 deletions
diff --git a/configure.in b/configure.in index 3849c362eec..6d5bc07ba9a 100644 --- a/configure.in +++ b/configure.in @@ -1884,6 +1884,15 @@ dnl MYSQL_CHECK_TIME_T +dnl +dnl check size of time_t +dnl + +AC_CHECK_SIZEOF(time_t, 8) +if test "$ac_cv_sizeof_time_t" -eq 0 +then + AC_MSG_ERROR("MySQL needs a time_t type.") +fi # do we need #pragma interface/#pragma implementation ? # yes if it's gcc 2.x, and not icc pretending to be gcc, and not cygwin diff --git a/include/config-win.h b/include/config-win.h index f802bbbbad8..939c3ae6f88 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -169,6 +169,11 @@ typedef uint rf_SetTimer; #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 #define SIZEOF_OFF_T 8 +/* + The size of time_t depends on the compiler. + But it's 8 for all the supported VC versions. +*/ +#define SIZEOF_TIME_T 8 #ifdef _WIN64 #define SIZEOF_CHARP 8 #else diff --git a/include/my_time.h b/include/my_time.h index 58995f1bf62..0bbb83b78b7 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -52,6 +52,19 @@ typedef long my_time_t; /* two-digit years < this are 20..; >= this are 19.. */ #define YY_PART_YEAR 70 +/* + check for valid times only if the range of time_t is greater than + the range of my_time_t +*/ +#if SIZEOF_TIME_T > 4 || defined(TIME_T_UNSIGNED) +# define IS_TIME_T_VALID_FOR_TIMESTAMP(x) \ + ((x) <= TIMESTAMP_MAX_VALUE && \ + (x) >= TIMESTAMP_MIN_VALUE) +#else +# define IS_TIME_T_VALID_FOR_TIMESTAMP(x) \ + ((x) >= TIMESTAMP_MIN_VALUE) +#endif + /* Flags to str_to_datetime */ #define TIME_FUZZY_DATE 1 #define TIME_DATETIME_ONLY 2 diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index 48e837f180f..5112aececa4 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -1301,6 +1301,23 @@ SELECT '2008-02-18' + INTERVAL 1 FRAC_SECOND; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FRAC_SECOND' at line 1 SELECT '2008-02-18' - INTERVAL 1 FRAC_SECOND; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FRAC_SECOND' at line 1 +# +# Bug #52315 part 2 : utc_date() crashes when system time > year 2037 +# +SET TIMESTAMP=-147490000; +SELECT UTC_TIMESTAMP(); +SET TIMESTAMP=2147483648; +SELECT UTC_TIMESTAMP(); +SET TIMESTAMP=2147483646; +SELECT UTC_TIMESTAMP(); +SET TIMESTAMP=2147483647; +SELECT UTC_TIMESTAMP(); +SET TIMESTAMP=0; +SELECT UTC_TIMESTAMP(); +SET TIMESTAMP=-1; +SELECT UTC_TIMESTAMP(); +SET TIMESTAMP=1; +SELECT UTC_TIMESTAMP(); End of 5.0 tests select date_sub("0050-01-01 00:00:01",INTERVAL 2 SECOND); date_sub("0050-01-01 00:00:01",INTERVAL 2 SECOND) diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 8fce7072319..032615ff56f 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -819,6 +819,25 @@ SELECT '2008-02-18' + INTERVAL 1 FRAC_SECOND; --error ER_PARSE_ERROR SELECT '2008-02-18' - INTERVAL 1 FRAC_SECOND; + +--echo # +--echo # Bug #52315 part 2 : utc_date() crashes when system time > year 2037 +--echo # + +--disable_result_log +--error ER_WRONG_VALUE_FOR_VAR +SET TIMESTAMP=-147490000; SELECT UTC_TIMESTAMP(); +--error ER_WRONG_VALUE_FOR_VAR +SET TIMESTAMP=2147483648; SELECT UTC_TIMESTAMP(); +SET TIMESTAMP=2147483646; SELECT UTC_TIMESTAMP(); +SET TIMESTAMP=2147483647; SELECT UTC_TIMESTAMP(); +SET TIMESTAMP=0; SELECT UTC_TIMESTAMP(); +--error ER_WRONG_VALUE_FOR_VAR +SET TIMESTAMP=-1; SELECT UTC_TIMESTAMP(); +SET TIMESTAMP=1; SELECT UTC_TIMESTAMP(); +--enable_result_log + + --echo End of 5.0 tests # diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index 74d5c8450a2..2513f4fbcc8 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -791,7 +791,7 @@ SET @@myisam_mmap_size= 500M; --echo # Bug #52315: utc_date() crashes when system time > year 2037 --echo # ---error 0, ER_UNKNOWN_ERROR +--error 0, ER_WRONG_VALUE_FOR_VAR SET TIMESTAMP=2*1024*1024*1024; --echo #Should not crash --disable_result_log diff --git a/sql-common/my_time.c b/sql-common/my_time.c index c4e917801d5..ca11c54a999 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -992,7 +992,7 @@ my_system_gmt_sec(const MYSQL_TIME *t_src, long *my_timezone, with unsigned time_t tmp+= shift*86400L might result in a number, larger then TIMESTAMP_MAX_VALUE, so another check will work. */ - if ((tmp < TIMESTAMP_MIN_VALUE) || (tmp > TIMESTAMP_MAX_VALUE)) + if (!IS_TIME_T_VALID_FOR_TIMESTAMP(tmp)) tmp= 0; return (my_time_t) tmp; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 2e36bc6ca66..54f93cccd5d 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3236,12 +3236,6 @@ static int init_common_variables(const char *conf_file_name, int argc, max_system_variables.pseudo_thread_id= (ulong)~0; server_start_time= flush_status_time= my_time(0); - /* TODO: remove this when my_time_t is 64 bit compatible */ - if (server_start_time >= (time_t) MY_TIME_T_MAX) - { - sql_print_error("This MySQL server doesn't support dates later then 2038"); - return 1; - } rpl_filter= new Rpl_filter; binlog_filter= new Rpl_filter; @@ -3280,6 +3274,13 @@ static int init_common_variables(const char *conf_file_name, int argc, */ mysql_bin_log.init_pthread_objects(); + /* TODO: remove this when my_time_t is 64 bit compatible */ + if (!IS_TIME_T_VALID_FOR_TIMESTAMP(server_start_time)) + { + sql_print_error("This MySQL server doesn't support dates later then 2038"); + return 1; + } + if (gethostname(glob_hostname,sizeof(glob_hostname)) < 0) { strmake(glob_hostname, STRING_WITH_LEN("localhost")); diff --git a/sql/set_var.cc b/sql/set_var.cc index dcd65496a54..d297be3fc10 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -2699,14 +2699,14 @@ int set_var_collation_client::update(THD *thd) bool sys_var_timestamp::check(THD *thd, set_var *var) { - time_t val; + longlong val; var->save_result.ulonglong_value= var->value->val_int(); - val= (time_t) var->save_result.ulonglong_value; - if (val < (time_t) MY_TIME_T_MIN || val > (time_t) MY_TIME_T_MAX) + val= (longlong) var->save_result.ulonglong_value; + if (val != 0 && // this is how you set the default value + (val < TIMESTAMP_MIN_VALUE || val > TIMESTAMP_MAX_VALUE)) { - my_message(ER_UNKNOWN_ERROR, - "This version of MySQL doesn't support dates later than 2038", - MYF(0)); + char buf[64]; + my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "timestamp", llstr(val, buf)); return TRUE; } return FALSE; diff --git a/sql/sql_class.h b/sql/sql_class.h index cb0f6b5c2ae..b3e8fde8cda 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2036,7 +2036,7 @@ public: /*TODO: this will be obsolete when we have support for 64 bit my_time_t */ inline bool is_valid_time() { - return (start_time < (time_t) MY_TIME_T_MAX); + return (IS_TIME_T_VALID_FOR_TIMESTAMP(start_time)); } void set_time_after_lock() { utime_after_lock= my_micro_time(); } ulonglong current_utime() { return my_micro_time(); } |