diff options
author | unknown <msvensson@pilot.blaudden> | 2007-02-23 17:33:11 +0100 |
---|---|---|
committer | unknown <msvensson@pilot.blaudden> | 2007-02-23 17:33:11 +0100 |
commit | d8ba8b8c985d256cf607e6e1a86be6b1fc533673 (patch) | |
tree | a63d78e9b3f0c439c75d9e419dfadcd8a1c55a15 /sql/tztime.cc | |
parent | 44994c9dfc99293f0be30334e407a212747b8eae (diff) | |
download | mariadb-git-d8ba8b8c985d256cf607e6e1a86be6b1fc533673.tar.gz |
Bug#26536 func_time failure on vm-win2003-64-b, occurs every time
- Avoid overflow in sec_since_epoch by shifting the time
back 2 days for times close to the maximum range of my_time_t
- Improve comment about why we need my_time_t
- Patch will also fix timezone2.test
include/my_time.h:
Improve comment for my_time_t, especially that we require
it to be at least a 32bit unsigned type
sql/tztime.cc:
- Add assert in sec_since_epoch to guard it against broken down time
values that would cause overflow in my_time_t on systems with 32 bit
my_time_t
- Avoid overflow in sec_since_epoch by "shifting" the broken down
time back 2 days for times that are near the max value.c
Diffstat (limited to 'sql/tztime.cc')
-rw-r--r-- | sql/tztime.cc | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/sql/tztime.cc b/sql/tztime.cc index 91bd4471463..ac1fa4ddff8 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -780,6 +780,8 @@ gmt_sec_to_TIME(TIME *tmp, my_time_t sec_in_utc, const TIME_ZONE_INFO *sp) static my_time_t sec_since_epoch(int year, int mon, int mday, int hour, int min ,int sec) { + /* Guard against my_time_t overflow(on system with 32 bit my_time_t) */ + DBUG_ASSERT(!(year == TIMESTAMP_MAX_YEAR && mon == 1 && mday > 17)); #ifndef WE_WANT_TO_HANDLE_UNORMALIZED_DATES /* It turns out that only whenever month is normalized or unnormalized @@ -948,12 +950,12 @@ TIME_to_gmt_sec(const TIME *t, const TIME_ZONE_INFO *sp, */ if (shift) { - if (local_t > (my_time_t) (TIMESTAMP_MAX_VALUE - shift*86400L + + if (local_t > (my_time_t) (TIMESTAMP_MAX_VALUE - shift * SECS_PER_DAY + sp->revtis[i].rt_offset - saved_seconds)) { DBUG_RETURN(0); /* my_time_t overflow */ } - local_t+= shift*86400L; + local_t+= shift * SECS_PER_DAY; } if (sp->revtis[i].rt_type) @@ -1341,6 +1343,7 @@ my_time_t Time_zone_offset::TIME_to_gmt_sec(const TIME *t, my_bool *in_dst_time_gap) const { my_time_t local_t; + int shift= 0; /* Check timestamp range.we have to do this as calling function relies on @@ -1349,10 +1352,24 @@ Time_zone_offset::TIME_to_gmt_sec(const TIME *t, my_bool *in_dst_time_gap) const if (!validate_timestamp_range(t)) return 0; - local_t= sec_since_epoch(t->year, t->month, t->day, + /* + Do a temporary shift of the boundary dates to avoid + overflow of my_time_t if the time value is near it's + maximum range + */ + if ((t->year == TIMESTAMP_MAX_YEAR) && (t->month == 1) && t->day > 4) + shift= 2; + + local_t= sec_since_epoch(t->year, t->month, (t->day - shift), t->hour, t->minute, t->second) - offset; + if (shift) + { + /* Add back the shifted time */ + local_t+= shift * SECS_PER_DAY; + } + if (local_t >= TIMESTAMP_MIN_VALUE && local_t <= TIMESTAMP_MAX_VALUE) return local_t; |