]> err.no Git - varnish/commitdiff
Use pdiff() to guard against negative point differences
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 25 Sep 2007 07:19:54 +0000 (07:19 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 25 Sep 2007 07:19:54 +0000 (07:19 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2022 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_fetch.c
varnish-cache/bin/varnishd/cache_hash.c
varnish-cache/bin/varnishd/cache_http.c
varnish-cache/bin/varnishd/hash_classic.c

index b62bfa7d26b7534859fb2d203300cf12cec6771a..47a94373c0484c71c6cb334b70019b372249509c 100644 (file)
@@ -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);
index 5c697787e99e6e178108558d5118e9a2702bc0ad..e72fff873d1b24e91f774659efdb2b2d6f764fb2 100644 (file)
@@ -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);
index f7d0f47bdff5a8589af130694f87f525f460ec02..661ef9668fe818287a05fe9ed194a1ff5823cb61 100644 (file)
@@ -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);
index fd02556df504ed38a6d6a7956cd3c658e9be787e..5ad212ce32dbb87d4c264fc69902efe5372b7e81 100644 (file)
@@ -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;