[master] 92e77b8 Introduce WS_Inside() to reduce the amount of grubbing around inside struct ws.

Poul-Henning Kamp phk at FreeBSD.org
Wed Feb 15 12:54:04 CET 2017


commit 92e77b873d0a0744bfc9fd1e0ba83545c226e750
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Feb 15 11:22:00 2017 +0000

    Introduce WS_Inside() to reduce the amount of grubbing around
    inside struct ws.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index cf6e317..6bd88e4 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1068,6 +1068,7 @@ void *WS_Copy(struct ws *ws, const void *str, int len);
 uintptr_t WS_Snapshot(struct ws *ws);
 int WS_Overflowed(const struct ws *ws);
 void *WS_Printf(struct ws *ws, const char *fmt, ...) __v_printflike(2, 3);
+int WS_Inside(const struct ws *, const void *, const void *);
 
 /* cache_rfc2616.c */
 void RFC2616_Ttl(struct busyobj *, double now, double *t_origin,
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 23bad44..873bd8a 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -1097,7 +1097,7 @@ http_CopyHome(const struct http *hp)
 			assert(u < HTTP_HDR_FIRST);
 			continue;
 		}
-		if (hp->hd[u].b >= hp->ws->s && hp->hd[u].e <= hp->ws->e)
+		if (WS_Inside(hp->ws, hp->hd[u].b, hp->hd[u].e))
 			continue;
 
 		l = Tlen(hp->hd[u]);
diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c
index be68575..ec6b2bc 100644
--- a/bin/varnishd/cache/cache_ws.c
+++ b/bin/varnishd/cache/cache_ws.c
@@ -59,6 +59,21 @@ WS_Assert(const struct ws *ws)
 	assert(*ws->e == 0x15);
 }
 
+int
+WS_Inside(const struct ws *ws, const void *bb, const void *ee)
+{
+	const char *b = bb;
+	const char *e = ee;
+
+	WS_Assert(ws);
+	if (b < ws->s || b >= ws->e)
+		return (0);
+	if (e != NULL && (e < b || e > ws->e))
+		return (0);
+	return (1);
+}
+
+
 /*
  * NB: The id must be max 3 char and lower-case.
  * (upper-case the first char to indicate overflow)
diff --git a/bin/varnishd/http2/cache_http2_deliver.c b/bin/varnishd/http2/cache_http2_deliver.c
index b69b45d..f21631c 100644
--- a/bin/varnishd/http2/cache_http2_deliver.c
+++ b/bin/varnishd/http2/cache_http2_deliver.c
@@ -137,7 +137,7 @@ h2_deliver(struct req *req, struct boc *boc, int sendbody)
 
 	hp = req->resp;
 	for (u = HTTP_HDR_FIRST; u < hp->nhd; u++) {
-		assert((char*)p < req->ws->e);
+		assert(WS_Inside(req->ws, p, NULL));
 
 		r = strchr(hp->hd[u].b, ':');
 		AN(r);
@@ -194,7 +194,7 @@ h2_deliver(struct req *req, struct boc *boc, int sendbody)
 
 		memcpy(p, r, sz);
 		p += sz;
-		assert((char*)p < req->ws->e);
+		assert(WS_Inside(req->ws, p, NULL));
 	}
 	sz = (char*)p - req->ws->f;
 



More information about the varnish-commit mailing list