From b07d72c6c1075efa6b64c67758566426c22c5225 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Wed, 21 Jun 2023 21:46:17 +0200 Subject: 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 Tested-by: Jenkins --- tools/source/datetime/ttime.cxx | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tools') 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 + -- cgit