From 1010496d4a1c101ab759bbea6c010503398554b5 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Mon, 29 Feb 2016 12:46:47 +0100 Subject: timespec_sub_ms: fixed operation in 32-bit systems --- lib/state.c | 11 +++++++++-- 1 file 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 #include #include +#include #include /* 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; + } } /** -- cgit v1.2.1