[master] 6c9021d Add an assert to ensure that our estimate of struct http size matches the actual size later on.

Poul-Henning Kamp phk at FreeBSD.org
Mon Apr 3 21:30:07 CEST 2017


commit 6c9021d9f5ed89ebcd597d7ef144b1886e370111
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Apr 3 19:18:33 2017 +0000

    Add an assert to ensure that our estimate of struct http size
    matches the actual size later on.
    
    Inspired by: #2298

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 5bc79d7..bc79aa3 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -749,7 +749,7 @@ void VGZ_UpdateObj(const struct vfp_ctx *, struct vgz*, enum vgz_ua_e);
 /* cache_http.c */
 unsigned HTTP_estimate(unsigned nhttp);
 void HTTP_Copy(struct http *to, const struct http * const fm);
-struct http *HTTP_create(void *p, uint16_t nhttp);
+struct http *HTTP_create(void *p, uint16_t nhttp, unsigned);
 const char *http_Status2Reason(unsigned, const char **);
 unsigned http_EstimateWS(const struct http *fm, unsigned how);
 void http_PutResponse(struct http *to, const char *proto, uint16_t status,
diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c
index 8fbcf43..0b9d62f 100644
--- a/bin/varnishd/cache/cache_busyobj.c
+++ b/bin/varnishd/cache/cache_busyobj.c
@@ -101,17 +101,17 @@ VBO_GetBusyObj(struct worker *wrk, const struct req *req)
 	nhttp = (uint16_t)cache_param->http_max_hdr;
 	sz = HTTP_estimate(nhttp);
 
-	bo->bereq0 = HTTP_create(p, nhttp);
+	bo->bereq0 = HTTP_create(p, nhttp, sz);
 	p += sz;
 	p = (void*)PRNDUP(p);
 	assert(p < bo->end);
 
-	bo->bereq = HTTP_create(p, nhttp);
+	bo->bereq = HTTP_create(p, nhttp, sz);
 	p += sz;
 	p = (void*)PRNDUP(p);
 	assert(p < bo->end);
 
-	bo->beresp = HTTP_create(p, nhttp);
+	bo->beresp = HTTP_create(p, nhttp, sz);
 	p += sz;
 	p = (void*)PRNDUP(p);
 	assert(p < bo->end);
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 5d900bf..d18ca52 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -147,7 +147,7 @@ HTTP_estimate(unsigned nhttp)
 }
 
 struct http *
-HTTP_create(void *p, uint16_t nhttp)
+HTTP_create(void *p, uint16_t nhttp, unsigned len)
 {
 	struct http *hp;
 
@@ -156,6 +156,7 @@ HTTP_create(void *p, uint16_t nhttp)
 	hp->hd = (void*)(hp + 1);
 	hp->shd = nhttp;
 	hp->hdf = (void*)(hp->hd + nhttp);
+	assert((unsigned char*)p + len == hp->hdf + nhttp);
 	return (hp);
 }
 
diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c
index 1899bb0..b95fc9e 100644
--- a/bin/varnishd/cache/cache_req.c
+++ b/bin/varnishd/cache/cache_req.c
@@ -77,17 +77,17 @@ Req_New(const struct worker *wrk, struct sess *sp)
 	nhttp = (uint16_t)cache_param->http_max_hdr;
 	hl = HTTP_estimate(nhttp);
 
-	req->http = HTTP_create(p, nhttp);
+	req->http = HTTP_create(p, nhttp, hl);
 	p += hl;
 	p = (void*)PRNDUP(p);
 	assert(p < e);
 
-	req->http0 = HTTP_create(p, nhttp);
+	req->http0 = HTTP_create(p, nhttp, hl);
 	p += hl;
 	p = (void*)PRNDUP(p);
 	assert(p < e);
 
-	req->resp = HTTP_create(p, nhttp);
+	req->resp = HTTP_create(p, nhttp, hl);
 	p += hl;
 	p = (void*)PRNDUP(p);
 	assert(p < e);



More information about the varnish-commit mailing list