From ce87b7e14cbf886e0f2279a322b87267a73071a0 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Fri, 17 Aug 2012 13:24:24 -0500 Subject: [PATCH] unix: fix integer overflow in uv_hrtime Conversion to nanoseconds was overflowing with 32-bit builds. --- src/unix/cygwin.c | 2 +- src/unix/freebsd.c | 2 +- src/unix/linux/linux-core.c | 2 +- src/unix/netbsd.c | 2 +- src/unix/openbsd.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/unix/cygwin.c b/src/unix/cygwin.c index a99779d4..183beb32 100644 --- a/src/unix/cygwin.c +++ b/src/unix/cygwin.c @@ -35,7 +35,7 @@ uint64_t uv_hrtime() { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (ts.tv_sec * NANOSEC + ts.tv_nsec); + return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); } void uv_loadavg(double avg[3]) { diff --git a/src/unix/freebsd.c b/src/unix/freebsd.c index be8006c5..0528835f 100644 --- a/src/unix/freebsd.c +++ b/src/unix/freebsd.c @@ -57,7 +57,7 @@ static char *process_title; uint64_t uv_hrtime(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (ts.tv_sec * NANOSEC + ts.tv_nsec); + return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); } diff --git a/src/unix/linux/linux-core.c b/src/unix/linux/linux-core.c index 34f48a94..c77c81cc 100644 --- a/src/unix/linux/linux-core.c +++ b/src/unix/linux/linux-core.c @@ -71,7 +71,7 @@ static struct { uint64_t uv_hrtime() { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (ts.tv_sec * NANOSEC + ts.tv_nsec); + return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); } diff --git a/src/unix/netbsd.c b/src/unix/netbsd.c index a1a7091b..5f7a8484 100644 --- a/src/unix/netbsd.c +++ b/src/unix/netbsd.c @@ -38,7 +38,7 @@ uint64_t uv_hrtime(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (ts.tv_sec * NANOSEC + ts.tv_nsec); + return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); } void uv_loadavg(double avg[3]) { diff --git a/src/unix/openbsd.c b/src/unix/openbsd.c index 865f8e9e..a18674fa 100644 --- a/src/unix/openbsd.c +++ b/src/unix/openbsd.c @@ -46,7 +46,7 @@ static char *process_title; uint64_t uv_hrtime(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (ts.tv_sec * NANOSEC + ts.tv_nsec); + return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); }