diff options
author | Lionel Elie Mamane <lionel@mamane.lu> | 2017-08-02 15:27:57 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2017-08-08 15:27:37 +0200 |
commit | de8c0152157bb32a6df9b6d4ac4102aef8e8a384 (patch) | |
tree | b111c9fc992d8edb35fdccdc510f69282c0f3ced | |
parent | d816fb9e6cb0e5f50142e7fc9c50b949e0f006e8 (diff) |
tdf#110997 protect calls to implBuildFromRelative from year overflow
Change-Id: I5c6768766673832b7271292af85db1b76e51042c
Reviewed-on: https://gerrit.libreoffice.org/40683
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
-rw-r--r-- | connectivity/source/commontools/dbconversion.cxx | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/connectivity/source/commontools/dbconversion.cxx b/connectivity/source/commontools/dbconversion.cxx index 5be258a7e698..9baca9bebb80 100644 --- a/connectivity/source/commontools/dbconversion.cxx +++ b/connectivity/source/commontools/dbconversion.cxx @@ -42,6 +42,16 @@ namespace const sal_Int64 hourMask = 10000000000000LL; const double fNanoSecondsPerDay = nanoSecInSec * secInMin * minInHour * 24.0; + + // 32767-12-31 in "(days since 0001-01-01) + 1" format + const sal_Int32 maxDays = 11967896; + // -32768-01-01 in "(days since 0001-01-01) + 1" format + // Yes, I know it is currently unused. Will have to be used + // when we implement negative years. Writing down the correct + // value for future reference. + // *** Please don't remove just because it is unused *** + // Lionel Élie Mamane 2017-08-02 + // const sal_Int32 minDays = -11968270; } @@ -269,8 +279,15 @@ namespace dbtools sal_Int32 nTempDays = implRelativeToAbsoluteNull( _rDate ); nTempDays += nDays; - // TODO: can we remove that check? Would allow dates before 1900. - if ( nTempDays <= 0 ) + if ( nTempDays > maxDays ) + { + _rDate.Day = 31; + _rDate.Month = 12; + _rDate.Year = 9999; + } + // TODO: can we replace that check by minDays? Would allow dates BCE + // implBuildFromRelative probably needs to be updated for the "no year 0" question + else if ( nTempDays <= 0 ) { _rDate.Day = 1; _rDate.Month = 1; @@ -285,8 +302,15 @@ namespace dbtools sal_Int32 nTempDays = implRelativeToAbsoluteNull( _rDate ); nTempDays -= nDays; - // TODO: can we remove that check? Would allow dates before 1900. - if ( nTempDays <= 0 ) + if ( nTempDays > maxDays ) + { + _rDate.Day = 31; + _rDate.Month = 12; + _rDate.Year = 9999; + } + // TODO: can we replace that check by minDays? Would allow dates BCE + // implBuildFromRelative probably needs to be updated for the "no year 0" question + else if ( nTempDays <= 0 ) { _rDate.Day = 1; _rDate.Month = 1; |