From 1b22c92d46f3f98af781853c3e16190c686bbd9b Mon Sep 17 00:00:00 2001 From: Marq Schneider Date: Sun, 18 Jul 2010 13:41:04 -0500 Subject: Applied patches from OpenBSD to fix addrinfo and HTTP. Applied OpenBSD patches from Nicholas Marriott. Closes GH-12 --- btpd/addrinfo.c | 2 +- misc/http_client.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/btpd/addrinfo.c b/btpd/addrinfo.c index 1ea3614..bea2d31 100644 --- a/btpd/addrinfo.c +++ b/btpd/addrinfo.c @@ -52,7 +52,7 @@ addrinfo_td_cb(void *arg) struct ai_ctx *ctx = arg; if (!ctx->cancel) ctx->cb(ctx->arg, ctx->error, ctx->res); - else if (ctx->error != 0) + else if (ctx->res != NULL) freeaddrinfo(ctx->res); free(ctx); } 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); -- cgit 1.4.1