summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2016-02-29 12:46:47 +0100
committerNikos Mavrogiannopoulos <nmav@redhat.com>2016-02-29 12:58:10 +0100
commit1010496d4a1c101ab759bbea6c010503398554b5 (patch)
tree1ec86a6fd483ac60e92a0053f2442af1c96db943
parent8dfbfcb54f60401dc1e1d18b44ef7a4fa1e119f2 (diff)
downloadgnutls-1010496d4a1c101ab759bbea6c010503398554b5.tar.gz
timespec_sub_ms: fixed operation in 32-bit systems
-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;
+ }
}
/**