summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/state.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/state.c b/lib/state.c
index 160cf043eb..2e125a1152 100644
--- a/lib/state.c
+++ b/lib/state.c
@@ -47,6 +47,7 @@
#include <system.h>
#include <random.h>
#include <fips.h>
+#include <intprops.h>
#include <gnutls/dtls.h>
/* These should really be static, but src/tests.c calls them. Make
@@ -1146,8 +1147,14 @@ gnutls_session_get_master_secret(gnutls_session_t session, gnutls_datum_t *secre
unsigned int timespec_sub_ms(struct timespec *a, struct timespec *b)
{
- return (a->tv_sec * 1000 + a->tv_nsec / (1000 * 1000) -
- (b->tv_sec * 1000 + b->tv_nsec / (1000 * 1000)));
+ time_t dsecs;
+
+ dsecs = a->tv_sec - b->tv_sec;
+ if (!INT_MULTIPLY_OVERFLOW(dsecs, 1000)) {
+ return (dsecs*1000 + (a->tv_nsec - b->tv_nsec) / (1000 * 1000));
+ } else {
+ return UINT_MAX;
+ }
}
/**