[master] 4ebc3cfec Make it possible to override the initial digest, and explain in a comment why it is not necessary.

Poul-Henning Kamp phk at FreeBSD.org
Fri Feb 12 08:11:09 UTC 2021


commit 4ebc3cfec133586cd8c4a715d8de18efb76402f1
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Feb 12 08:03:12 2021 +0000

    Make it possible to override the initial digest, and explain in
    a comment why it is not necessary.
    
    Only call vcl_hash{} if the initial hash is still intact when we get there.

diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index d82955a96..df1a674cf 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -76,6 +76,14 @@
 REQ_STEPS
 #undef REQ_STEP
 
+/*
+ * In this specific context we use SHA256 only as a very good
+ * hashing function.  That renders most of the normal concerns
+ * about salting & seeding moot.  However, if for some reason
+ * you want to salt your hashes, this is where you do it.
+ */
+static const uint8_t initial_digest[DIGEST_LEN];
+
 /*--------------------------------------------------------------------
  * Handle "Expect:" and "Connection:" on incoming request
  */
@@ -914,6 +922,8 @@ cnt_recv(struct worker *wrk, struct req *req)
 		return (REQ_FSM_DONE);
 	}
 
+	memcpy(req->digest, initial_digest, sizeof req->digest);
+
 	VCL_recv_method(req->vcl, wrk, req, NULL, NULL);
 
 	if (wrk->handling == VCL_RET_FAIL) {
@@ -955,12 +965,13 @@ cnt_recv(struct worker *wrk, struct req *req)
 		}
 	}
 
-	memset(req->digest, 0, sizeof req->digest);
-	VCL_hash_method(req->vcl, wrk, req, NULL, NULL);
-	if (wrk->handling == VCL_RET_FAIL)
-		recv_handling = wrk->handling;
-	else
-		assert(wrk->handling == VCL_RET_LOOKUP);
+	if (!memcmp(req->digest, initial_digest, sizeof req->digest)) {
+		VCL_hash_method(req->vcl, wrk, req, NULL, NULL);
+		if (wrk->handling == VCL_RET_FAIL)
+			recv_handling = wrk->handling;
+		else
+			assert(wrk->handling == VCL_RET_LOOKUP);
+	}
 
 	switch (recv_handling) {
 	case VCL_RET_VCL:


More information about the varnish-commit mailing list