]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
tcpreceiver: Better handling of "clock moved backward" events
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 24 Nov 2023 09:57:37 +0000 (10:57 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 24 Nov 2023 09:57:37 +0000 (10:57 +0100)
pdns/tcpreceiver.cc

index e76be9000100ffb2458cd6fc1d7d95bef0119fab..2ea87fbf7c5a2aeb7177ff9ff90c4d84042b6a1e 100644 (file)
@@ -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<decltype(elapsed)>(remainingTotal)) {
+      if (elapsed >= static_cast<decltype(elapsed)>(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<unsigned int >(maxConnectionDuration - elapsed);
+    if (elapsed > 0) {
+      remainingTime = static_cast<unsigned int >(maxConnectionDuration - elapsed);
+    }
   }
   return false;
 }