[3.0] a5e2100 Make sure we neuter the next entry after the one we just created to prevent old junk on the workspace from being taken for valid.

Tollef Fog Heen tfheen at varnish-cache.org
Wed Aug 17 11:25:27 CEST 2011


commit a5e2100e65c8a75165d16244b9fddab2333b2edd
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jun 22 09:29:46 2011 +0000

    Make sure we neuter the next entry after the one we just created
    to prevent old junk on the workspace from being taken for valid.

diff --git a/bin/varnishd/cache_vary.c b/bin/varnishd/cache_vary.c
index 27abf74..01816f6 100644
--- a/bin/varnishd/cache_vary.c
+++ b/bin/varnishd/cache_vary.c
@@ -209,13 +209,19 @@ VRY_Match(const struct sess *sp, const uint8_t *vary)
 				oflo = 1;
 			}
 
-			/* We MUST have space for one entry */
-			assert(vsp + ln < sp->wrk->vary_e);
+			/*
+			 * We MUST have space for one entry and the end marker
+			 * after it, which prevents old junk from confusing us
+			 */
+			assert(vsp + ln + 2 < sp->wrk->vary_e);
 
 			vbe16enc(vsp, (uint16_t)lh);
 			memcpy(vsp + 2, vary + 2, vary[2] + 2);
-			if (h != NULL && e != NULL)
+			if (h != NULL && e != NULL) {
 				memcpy(vsp + 2 + vsp[2] + 2, h, e - h);
+				vsp[2 + vary[2] + 2 + (e - h) + 2] = '\0';
+			} else
+				vsp[2 + vary[2] + 2 + 2] = '\0';
 
 			i = vry_cmp(&vary, &vsp);
 			assert(i != 1);	/* hdr must be the same now */



More information about the varnish-commit mailing list