]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix livelocking in peerDigestHandleReply (#698)
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Mon, 27 Jul 2020 15:28:31 +0000 (15:28 +0000)
committerAmos Jeffries <yadij@users.noreply.github.com>
Tue, 11 Aug 2020 05:13:21 +0000 (17:13 +1200)
peerDigestHandleReply() was missing a premature EOF check. The existing
peerDigestFetchedEnough() cannot detect EOF because it does not have
access to receivedData.length used to indicate the EOF condition. We did
not adjust peerDigestFetchedEnough() because it is abused to check both
post-I/O state and the state after each digest processing step. The
latter invocations lack access to receivedData.length and should not
really bother with EOF anyway.

src/peer_digest.cc

index d48340f9786008d9566dd0dddc6ed6b9493a287d..265f161839b0bb174195a9caf4af107adc8c8f66 100644 (file)
@@ -483,6 +483,15 @@ peerDigestHandleReply(void *data, StoreIOBuffer receivedData)
 
     } while (cbdataReferenceValid(fetch) && prevstate != fetch->state && fetch->bufofs > 0);
 
+    // Check for EOF here, thus giving the parser one extra run. We could avoid this overhead by
+    // checking at the beginning of this function. However, in this case, we would have to require
+    // that the parser does not regard EOF as a special condition (it is true now but may change
+    // in the future).
+    if (!receivedData.length) { // EOF
+        peerDigestFetchAbort(fetch, fetch->buf, "premature end of digest reply");
+        return;
+    }
+
     /* Update the copy offset */
     fetch->offset += receivedData.length;