1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-17 12:31:25 +00:00

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.
This commit is contained in:
wm4 2014-02-02 16:52:20 +01:00
parent 7aa3726c9a
commit dd264ebe9d

View File

@ -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) {