diff options
author | Eike Rathke <erack@redhat.com> | 2023-06-21 21:46:17 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2023-06-23 14:27:05 +0200 |
commit | b07d72c6c1075efa6b64c67758566426c22c5225 (patch) | |
tree | 8d08c1104abb86a748807f167fee59e1d1def214 /tools/source/datetime | |
parent | d0a9d04d2287da456317c5a59af3ccbe3b98b977 (diff) |
Clamp and assert maximum hours value in Time::init()
Change-Id: Ia777222f3c797b90663b55499a57025e410b1d70
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153407
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
Diffstat (limited to 'tools/source/datetime')
-rw-r--r-- | tools/source/datetime/ttime.cxx | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/source/datetime/ttime.cxx b/tools/source/datetime/ttime.cxx index 148bf0cbecc6..fcfa2e080e99 100644 --- a/tools/source/datetime/ttime.cxx +++ b/tools/source/datetime/ttime.cxx @@ -125,6 +125,18 @@ void tools::Time::init( sal_uInt32 nHour, sal_uInt32 nMin, sal_uInt32 nSec, sal_ nHour += nMin / minInHour; nMin %= minInHour; + // 922337 * HOUR_MASK = 9223370000000000000 largest possible value, 922338 + // would be -9223364073709551616. + assert(HOUR_MASK * nHour >= 0 && "use tools::Duration with days instead!"); + if (HOUR_MASK * nHour < 0) + nHour = 922337; + + // But as is, GetHour() retrieves only sal_uInt16. Though retrieving in + // nanoseconds or milliseconds might be possible this is all crap. + assert(nHour <= SAL_MAX_UINT16 && "use tools::Duration with days instead!"); + if (nHour > SAL_MAX_UINT16) + nHour = SAL_MAX_UINT16; + // construct time nTime = nNanoSec + nSec * SEC_MASK + |