]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make isc_time_nowplusinterval consistent with other functions 5760/head
authorMartin Basti <mbasti@isc.org>
Thu, 9 Jul 2026 12:25:33 +0000 (14:25 +0200)
committerMartin Basti <mbasti@isc.org>
Wed, 22 Jul 2026 09:17:36 +0000 (11:17 +0200)
isc_time_nowplusinterval was using different code than the
rest of functions in the time.c. Replace custom overflow logic
with ckd_add macro.

lib/isc/time.c

index 9806298e676df2a38b10d7d5453e515342b6c95d..58681988b1ac5db86c1a6c3b1e07fff415b8c843 100644 (file)
@@ -148,19 +148,19 @@ isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i) {
                return ISC_R_UNEXPECTED;
        }
 
-       /*
-        * Ensure the resulting seconds value fits in the size of an
-        * unsigned int.
-        */
-       if ((unsigned int)ts.tv_sec > UINT_MAX - i->seconds) {
+       /* Seconds */
+       if (ckd_add(&t->seconds, ts.tv_sec, i->seconds)) {
                return ISC_R_RANGE;
        }
 
-       t->seconds = ts.tv_sec + i->seconds;
+       /* Nanoseconds */
        t->nanoseconds = ts.tv_nsec + i->nanoseconds;
        if (t->nanoseconds >= NS_PER_SEC) {
-               t->seconds++;
+               if (t->seconds == UINT_MAX) {
+                       return ISC_R_RANGE;
+               }
                t->nanoseconds -= NS_PER_SEC;
+               t->seconds++;
        }
 
        return ISC_R_SUCCESS;