From: Remi Gacogne Date: Fri, 24 Nov 2023 09:57:37 +0000 (+0100) Subject: tcpreceiver: Better handling of "clock moved backward" events X-Git-Tag: rec-5.0.0-rc1~3^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=62a34cfd72b18dcffb89770c19460d0a91ef4974;p=thirdparty%2Fpdns.git tcpreceiver: Better handling of "clock moved backward" events --- diff --git a/pdns/tcpreceiver.cc b/pdns/tcpreceiver.cc index e76be90001..2ea87fbf7c 100644 --- a/pdns/tcpreceiver.cc +++ b/pdns/tcpreceiver.cc @@ -132,11 +132,13 @@ static int readnWithTimeout(int fd, void* buffer, unsigned int n, unsigned int i if (totalTimeout) { time_t now = time(nullptr); const auto elapsed = now - start; - if (elapsed > 0 && elapsed >= static_cast(remainingTotal)) { + if (elapsed >= static_cast(remainingTotal)) { throw NetworkError("Timeout while reading data"); } start = now; - remainingTotal -= elapsed; + if (elapsed > 0) { + remainingTotal -= elapsed; + } } } return n; @@ -197,10 +199,12 @@ static bool maxConnectionDurationReached(unsigned int maxConnectionDuration, tim { if (maxConnectionDuration) { time_t elapsed = time(nullptr) - start; - if (elapsed > 0 && elapsed >= maxConnectionDuration) { + if (elapsed >= maxConnectionDuration) { return true; } - remainingTime = static_cast(maxConnectionDuration - elapsed); + if (elapsed > 0) { + remainingTime = static_cast(maxConnectionDuration - elapsed); + } } return false; }