tools/source/datetime/ttime.cxx |   12 ++++++++++++
 1 file changed, 12 insertions(+)

New commits:
commit b07d72c6c1075efa6b64c67758566426c22c5225
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Wed Jun 21 21:46:17 2023 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Fri Jun 23 14:27:05 2023 +0200

    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 <er...@redhat.com>
    Tested-by: Jenkins

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 +

Reply via email to