From 77addf78968e9b085631bfb665b54146337ee51f Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 25 Sep 2007 07:19:54 +0000 Subject: [PATCH] Use pdiff() to guard against negative point differences git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2022 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_fetch.c | 6 +++--- varnish-cache/bin/varnishd/cache_hash.c | 2 +- varnish-cache/bin/varnishd/cache_http.c | 14 +++++++------- varnish-cache/bin/varnishd/hash_classic.c | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index b62bfa7d..47a94373 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -157,7 +157,7 @@ fetch_chunked(struct sess *sp, int fd, struct http *hp) v = u; /* Handle anything left in our buffer first */ - i = bp - q; + i = pdiff(q, bp); assert(i >= 0); if (i > v) i = v; @@ -188,7 +188,7 @@ fetch_chunked(struct sess *sp, int fd, struct http *hp) assert(u == 0); /* We might still have stuff in our buffer */ - v = bp - q; + v = pdiff(q, bp); if (v > 0) memcpy(buf, q, v); q = bp = buf + v; @@ -322,7 +322,7 @@ Fetch(struct sess *sp) CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); /* Filter into object */ hp2 = &sp->obj->http; - len = hp->rx_e - hp->rx_s; + len = pdiff(hp->rx_s, hp->rx_e); len += 256; /* margin for content-length etc */ CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); diff --git a/varnish-cache/bin/varnishd/cache_hash.c b/varnish-cache/bin/varnishd/cache_hash.c index 5c697787..e72fff87 100644 --- a/varnish-cache/bin/varnishd/cache_hash.c +++ b/varnish-cache/bin/varnishd/cache_hash.c @@ -121,7 +121,7 @@ HSH_Compare(const struct sess *sp, const struct objhead *obj) return (i); b = obj->hash; for (u = 0; u < sp->ihashptr; u += 2) { - v = sp->hashptr[u + 1] - sp->hashptr[u]; + v = pdiff(sp->hashptr[u], sp->hashptr[u + 1]); i = memcmp(sp->hashptr[u], b, v); if (i) return (i); diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index f7d0f47b..661ef966 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -289,7 +289,7 @@ http_DoConnection(struct sess *sp) for (q = p + 1; *q; q++) if (*q == ',' || isspace(*q)) break; - i = q - p; + i = pdiff(p, q); if (i == 5 && !strncasecmp(p, "close", i)) sp->doclose = "Connection: close"; u = http_findhdr(hp, i, p); @@ -326,10 +326,10 @@ http_GetTail(struct http *hp, unsigned len, char **b, char **e) return (0); if (len == 0) - len = hp->pl_e - hp->pl_s; + len = pdiff(hp->pl_s, hp->pl_e); if (hp->pl_s + len > hp->pl_e) - len = hp->pl_e - hp->pl_s; + len = pdiff(hp->pl_s, hp->pl_e); if (len == 0) return (0); *b = hp->pl_s; @@ -351,7 +351,7 @@ http_Read(struct http *hp, int fd, void *p, unsigned len) u = 0; if (hp->pl_s < hp->pl_e) { - u = hp->pl_e - hp->pl_s; + u = pdiff(hp->pl_s, hp->pl_e); if (u > len) u = len; memcpy(b, hp->pl_s, u); @@ -617,7 +617,7 @@ http_RecvPrep(struct http *hp) hp->rx_e = hp->rx_s; if (hp->pl_s != NULL) { assert(hp->pl_s < hp->pl_e); - l = hp->pl_e - hp->pl_s; + l = pdiff(hp->pl_s, hp->pl_s); memmove(hp->rx_s, hp->pl_s, l); hp->rx_e = hp->rx_s + l; hp->pl_s = hp->pl_e = NULL; @@ -642,7 +642,7 @@ http_RecvSome(int fd, struct http *hp) unsigned l; int i; - l = (hp->ws->e - hp->rx_e) - 1; + l = pdiff(hp->rx_e, hp->ws->e) - 1; l /= 2; /* Don't fill all of workspace with read-ahead */ if (l <= 1) { VSL(SLT_HttpError, fd, "Received too much"); @@ -857,7 +857,7 @@ http_CopyHome(struct worker *w, int fd, struct http *hp) WSLH(w, htt, fd, hp, u); continue; } - l = hp->hd[u].e - hp->hd[u].b; + l = pdiff(hp->hd[u].b, hp->hd[u].e); p = WS_Alloc(hp->ws, l + 1); if (p != NULL) { WSLH(w, htt, fd, hp, u); diff --git a/varnish-cache/bin/varnishd/hash_classic.c b/varnish-cache/bin/varnishd/hash_classic.c index fd02556d..5ad212ce 100644 --- a/varnish-cache/bin/varnishd/hash_classic.c +++ b/varnish-cache/bin/varnishd/hash_classic.c @@ -132,7 +132,7 @@ hcl_lookup(struct sess *sp, struct objhead *noh) digest = ~0U; for (u = 0; u < sp->ihashptr; u += 2) { - v = sp->hashptr[u + 1] - sp->hashptr[u]; + v = pdiff(sp->hashptr[u], sp->hashptr[u + 1]); digest = crc32(digest, sp->hashptr[u], v); } digest ^= ~0U; -- 2.39.5