summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-02-02 16:52:20 +0100
committerwm4 <wm4@nowhere>2014-02-10 00:04:39 +0100
commitdd264ebe9d00c8cb22ed4d931d31293ff5b3cece (patch)
tree878b4a7e22a1a21a546231b9d6c2354a9ccc4148 /osdep
parent7aa3726c9acce93e10e69053f96a4338a1ece0b7 (diff)
downloadmpv-dd264ebe9d00c8cb22ed4d931d31293ff5b3cece.tar.bz2
mpv-dd264ebe9d00c8cb22ed4d931d31293ff5b3cece.tar.xz
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.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/threads.c3
1 files changed, 3 insertions, 0 deletions
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 <time.h>
#include <unistd.h>
#include <sys/time.h>
+#include <limits.h>
#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) {