about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarq Schneider <queueRAM@gmail.com>2010-07-18 13:41:04 -0500
committerMarq Schneider <queueRAM@gmail.com>2010-07-18 13:41:04 -0500
commit1b22c92d46f3f98af781853c3e16190c686bbd9b (patch)
treebced12b2ea3a1dc315f592b841f8a59910599a92
parent034ba1a5e4906d4f69dccea8d41108b5adbc780c (diff)
downloadbtpd-1b22c92d46f3f98af781853c3e16190c686bbd9b.tar.gz
btpd-1b22c92d46f3f98af781853c3e16190c686bbd9b.zip
Applied patches from OpenBSD to fix addrinfo and HTTP.
Applied OpenBSD patches from Nicholas Marriott.
Closes GH-12
-rw-r--r--btpd/addrinfo.c2
-rw-r--r--misc/http_client.c9
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);