diff options
Diffstat (limited to 'misc/http_client.c')
| -rw-r--r-- | misc/http_client.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/misc/http_client.c b/misc/http_client.c index 1b0d564..6a72533 100644 --- a/misc/http_client.c +++ b/misc/http_client.c @@ -213,7 +213,7 @@ static int http_parse(struct http_req *req, int len) { char *end, *numend; - size_t dlen; + size_t dlen, consumed; struct http_response res; again: switch (req->pstate) { @@ -230,6 +230,11 @@ again: else goto error; } + + /* req->rbuf.buf may be reallocated inside iobuf_write() + * so calculate the offset before that is called */ + consumed = end - (char *)req->rbuf.buf + dlen; + if (!iobuf_write(&req->rbuf, "", 1)) goto error; req->rbuf.off--; @@ -237,7 +242,7 @@ again: goto error; if (req->cancel) goto cancel; - iobuf_consumed(&req->rbuf, end - (char *)req->rbuf.buf + dlen); + iobuf_consumed(&req->rbuf, consumed); goto again; case PS_CHUNK_SIZE: assert(req->chunked); |