Permalink
Browse files

Introduce WS_Inside() to reduce the amount of grubbing around

inside struct ws.
  • Loading branch information...
1 parent c1cf8d3 commit 92e77b873d0a0744bfc9fd1e0ba83545c226e750 @bsdphk bsdphk committed Feb 15, 2017
@@ -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,
@@ -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]);
@@ -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)
@@ -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;

0 comments on commit 92e77b8

Please sign in to comment.