From b4e3f1a896989d1e5190e114b5bc05cd613ef646 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Wed, 9 Sep 2020 11:59:40 +0100 Subject: [PATCH] fix negative timeout resulting in select() EINVAL --- src/reqs.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/reqs.c b/src/reqs.c index 370b375..074b416 100644 --- a/src/reqs.c +++ b/src/reqs.c @@ -1177,13 +1177,18 @@ static void relay_connection (struct conn_s *connptr) last_access = time (NULL); for (;;) { - FD_ZERO (&rset); - FD_ZERO (&wset); - tv.tv_sec = config->idletimeout - difftime (time (NULL), last_access); tv.tv_usec = 0; + if (tv.tv_sec < 0) { + tdiff = config->idletimeout + 1; + goto e_timedout; + } + + FD_ZERO (&rset); + FD_ZERO (&wset); + if (buffer_size (connptr->sbuffer) > 0) FD_SET (connptr->client_fd, &wset); if (buffer_size (connptr->cbuffer) > 0) @@ -1198,6 +1203,7 @@ static void relay_connection (struct conn_s *connptr) if (ret == 0) { tdiff = difftime (time (NULL), last_access); if (tdiff > config->idletimeout) { + e_timedout:; log_message (LOG_INFO, "Idle Timeout (after select) as %g > %u.", tdiff, config->idletimeout);