summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2015-10-28 20:25:46 +0000
committertedu <tedu@openbsd.org>2015-10-28 20:25:46 +0000
commitfea0595179b0461883c96281b17f5a87502bf612 (patch)
tree6f8efaea320b62cee72b624f2a3742db8ab8c1bc
parenttwiddle with rlimit to give us a few more files. use rlimit as a hint as (diff)
downloadwireguard-openbsd-fea0595179b0461883c96281b17f5a87502bf612.tar.xz
wireguard-openbsd-fea0595179b0461883c96281b17f5a87502bf612.zip
bug in the request tree code: requests were being added to the tree before
the socket (the key) was being set. move the enqueue code later, and fix freerequest to only dequeue if socket is set.
-rw-r--r--usr.sbin/rebound/rebound.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/usr.sbin/rebound/rebound.c b/usr.sbin/rebound/rebound.c
index abca3156353..b62c9a3867c 100644
--- a/usr.sbin/rebound/rebound.c
+++ b/usr.sbin/rebound/rebound.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rebound.c,v 1.32 2015/10/28 20:20:35 tedu Exp $ */
+/* $OpenBSD: rebound.c,v 1.33 2015/10/28 20:25:46 tedu Exp $ */
/*
* Copyright (c) 2015 Ted Unangst <tedu@openbsd.org>
*
@@ -80,6 +80,9 @@ static TAILQ_HEAD(, dnscache) cachefifo;
static RB_HEAD(cachetree, dnscache) cachetree;
RB_PROTOTYPE_STATIC(cachetree, dnscache, cachenode, cachecmp)
+/*
+ * requests are kept on both fifo and tree, but only after socket s is set.
+ */
struct request {
int s;
int client;
@@ -167,12 +170,13 @@ freerequest(struct request *req)
conncount -= 2;
else
conncount -= 1;
- TAILQ_REMOVE(&reqfifo, req, fifo);
- RB_REMOVE(reqtree, &reqtree, req);
+ if (req->s != -1) {
+ TAILQ_REMOVE(&reqfifo, req, fifo);
+ RB_REMOVE(reqtree, &reqtree, req);
+ close(req->s);
+ }
if (req->client != -1)
close(req->client);
- if (req->s != -1)
- close(req->s);
if ((ent = req->cacheent) && !ent->resp) {
free(ent->req);
free(ent);
@@ -225,10 +229,9 @@ newrequest(int ud, struct sockaddr *remoteaddr)
return NULL;
conncount += 1;
- TAILQ_INSERT_TAIL(&reqfifo, req, fifo);
- RB_INSERT(reqtree, &reqtree, req);
req->ts = now;
req->ts.tv_sec += 30;
+ req->s = -1;
req->client = -1;
memcpy(&req->from, &from, fromlen);
@@ -263,6 +266,8 @@ newrequest(int ud, struct sockaddr *remoteaddr)
if (send(req->s, buf, r, 0) != r)
goto fail;
+ TAILQ_INSERT_TAIL(&reqfifo, req, fifo);
+ RB_INSERT(reqtree, &reqtree, req);
return req;
fail:
@@ -334,8 +339,6 @@ newtcprequest(int ld, struct sockaddr *remoteaddr)
return NULL;
conncount += 2;
- TAILQ_INSERT_TAIL(&reqfifo, req, fifo);
- RB_INSERT(reqtree, &reqtree, req);
req->ts = now;
req->ts.tv_sec += 30;
req->tcp = 1;
@@ -356,6 +359,8 @@ newtcprequest(int ld, struct sockaddr *remoteaddr)
return tcpphasetwo(req);
}
+ TAILQ_INSERT_TAIL(&reqfifo, req, fifo);
+ RB_INSERT(reqtree, &reqtree, req);
return req;
fail:
@@ -560,7 +565,7 @@ main(int argc, char **argv)
struct timespec ts, *timeout = NULL;
const char *conffile = "/etc/rebound.conf";
- if (0 && pledge("stdio inet proc id rpath", NULL) == -1)
+ if (pledge("stdio inet proc id rpath", NULL) == -1)
logerr("pledge failed");
while ((ch = getopt(argc, argv, "c:d")) != -1) {