diff options
author | unknown <tnurnberg@mysql.com> | 2006-05-16 03:32:24 +0200 |
---|---|---|
committer | unknown <tnurnberg@mysql.com> | 2006-05-16 03:32:24 +0200 |
commit | 6792c154aa731ee2848d8828e5aed5383498f944 (patch) | |
tree | 2e5e872fb3ab41cbe007ca6345f66bfd46672ad6 /sql-common | |
parent | c720b28caec346dc9a72e4eda6aa501bfd1b2e4d (diff) | |
download | mariadb-git-6792c154aa731ee2848d8828e5aed5383498f944.tar.gz |
Bug#18997: DATE_ADD and DATE_SUB perform year2K autoconversion magic on 4-digit year value
if input year for date_add() / date_sub() with INTERVAL is low enough for
calc_daynr() to possibly return incorrect results (calc_daynr() has no information
on whether the year is low because it was a two-digit year ('77) or because it
was a really low four-digit year (0077) and will indiscriminately try to turn the
value into a four-digit year by adding 1900 or 2000 respectively), the functions
will now throw NULL.
include/my_time.h:
new define YY_MAGIC_BELOW: if year is below this threshold, magic kicks in in
calc_daynr(). the idea is to convert two-digit years to four-digit ones, adding
1900 to values >= YY_PART_YEAR or adding 2000 otherwise.
current value of YY_MAGIC_BELOW derived from original code in calc_daynr()
mysql-test/r/func_time.result:
test where 2 digit -> 4 digit year magic kicks in, and whether we throw NULL when
it happens
mysql-test/t/func_time.test:
test where 2 digit -> 4 digit year magic kicks in, and whether we throw NULL when
it happens
sql-common/my_time.c:
use new const YY_MAGIC_BELOW, apply 2-digit -> 4-digit magic only to years
below this threshold.
sql/item_timefunc.cc:
throw NULL when year in date_add() / date_sub() would be affected by
2 digit -> 4 digit magic.
Diffstat (limited to 'sql-common')
-rw-r--r-- | sql-common/my_time.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/sql-common/my_time.c b/sql-common/my_time.c index c9d39260761..f75298e4f5d 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -689,7 +689,7 @@ long calc_daynr(uint year,uint month,uint day) if (year == 0 && month == 0 && day == 0) DBUG_RETURN(0); /* Skip errors */ - if (year < 200) + if (year < YY_MAGIC_BELOW) { if ((year=year+1900) < 1900+YY_PART_YEAR) year+=100; |