From: Ilya Bakhtin Date: Fri, 29 Sep 2023 14:23:04 +0000 (+0200) Subject: util/time: Prevent usecs overflow X-Git-Tag: suricata-8.0.0-beta1~1966 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3095ac0589228a4c63a466f5ff3b99bab98bf25;p=thirdparty%2Fsuricata.git util/time: Prevent usecs overflow This commit takes care of original seconds value and prevents the useconds field from overflowing pas its maximum value. Issue: 6372 --- diff --git a/src/util-time.h b/src/util-time.h index 9bbd8798dd..479f9a2b35 100644 --- a/src/util-time.h +++ b/src/util-time.h @@ -57,7 +57,11 @@ typedef struct { #define SCTIME_SECS(t) ((uint64_t)(t).secs) #define SCTIME_MSECS(t) (SCTIME_SECS(t) * 1000 + SCTIME_USECS(t) / 1000) #define SCTIME_ADD_SECS(ts, s) SCTIME_FROM_SECS((ts).secs + (s)) -#define SCTIME_ADD_USECS(ts, us) SCTIME_FROM_USECS((ts).usecs + (us)) +#define SCTIME_ADD_USECS(ts, us) \ + (SCTime_t) \ + { \ + .secs = (ts).secs + ((ts).usecs + (us)) / 1000000, .usecs = ((ts).usecs + (us)) % 1000000 \ + } #define SCTIME_FROM_SECS(s) \ (SCTime_t) \ { \