]> 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>
Sun, 9 Aug 2020 18:06:11 +0000 (06:06 +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 9a2abc38ad9c92d5f78e7c89abbd72d9559c6b3d..8d6becffea4d03b1b8a858180d135b05bc9afbfe 100644 (file)
@@ -484,6 +484,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;