Commit a857dbd0 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Use pdiff() to guard against negative point differences


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2022 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent af82f52c
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment