From dd264ebe9d00c8cb22ed4d931d31293ff5b3cece Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 2 Feb 2014 16:52:20 +0100 Subject: threads: avoid timeout calculation overflow It's quite possible to overflow the calculation by setting the timeout to high values. Limit it to INT_MAX, which should be safe. The issue is mainly the secs variable. timespec.tv_sec will normally be 64 bit on sane systems, and we assume it can't overflow by adding INT_MAX to it. --- osdep/threads.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'osdep') diff --git a/osdep/threads.c b/osdep/threads.c index 9a53d5c5c0..dcc3965b1d 100644 --- a/osdep/threads.c +++ b/osdep/threads.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "threads.h" @@ -36,6 +37,8 @@ static void get_pthread_time(struct timespec *out_ts) static void timespec_add_seconds(struct timespec *ts, double seconds) { + if (seconds > INT_MAX) + seconds = INT_MAX; unsigned long secs = (int)seconds; unsigned long nsecs = (seconds - secs) * 1000000000UL; if (nsecs + ts->tv_nsec >= 1000000000UL) { -- cgit v1.2.3