aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflorian2013-10-19 14:18:35 +0000
committerWynn Wolf Arbor2020-05-24 12:33:55 +0200
commit1483ec35ca0c0575168c67f6ccfb4244c798b65c (patch)
tree57ca8fef5b4899f70d8bb327d1fdb10838dc956b
parentda0da57b202826af381c742d75db2330f4f52ea6 (diff)
downloadslowcgi-1483ec35ca0c0575168c67f6ccfb4244c798b65c.tar.gz
Keep track of which fds were closed before and only close those still open. Otherwise if there are parallel requests and the timing is just right we were closing random fds from other connections. OK blambert
-rw-r--r--slowcgi.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/slowcgi.c b/slowcgi.c
index 79dfae3..f3c3f41 100644
--- a/slowcgi.c
+++ b/slowcgi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: slowcgi.c,v 1.17 2013/10/18 14:48:54 florian Exp $ */
+/* $OpenBSD: slowcgi.c,v 1.18 2013/10/19 14:18:35 florian Exp $ */
/*
* Copyright (c) 2013 David Gwynne <dlg@openbsd.org>
* Copyright (c) 2013 Florian Obser <florian@openbsd.org>
@@ -123,6 +123,9 @@ struct request {
struct event script_ev;
struct event script_err_ev;
struct event script_stdin_ev;
+ int stdin_fd_closed;
+ int stdout_fd_closed;
+ int stderr_fd_closed;
uint8_t script_flags;
uint8_t request_started;
};
@@ -418,6 +421,7 @@ slowcgi_accept(int fd, short events, void *arg)
c->buf_pos = 0;
c->buf_len = 0;
c->request_started = 0;
+ c->stdin_fd_closed = c->stdout_fd_closed = c->stderr_fd_closed = 0;
TAILQ_INIT(&c->response_head);
TAILQ_INIT(&c->stdin_head);
@@ -924,6 +928,10 @@ script_in(int fd, struct event *ev, struct request *c, uint8_t type)
}
event_del(ev);
close(fd);
+ if (type == FCGI_STDOUT)
+ c->stdout_fd_closed = 1;
+ else
+ c->stderr_fd_closed = 1;
}
}
@@ -953,6 +961,7 @@ script_out(int fd, short events, void *arg)
while ((node = TAILQ_FIRST(&c->stdin_head))) {
if (node->data_len == 0) { /* end of stdin marker */
close(fd);
+ c->stdin_fd_closed = 1;
break;
}
n = write(fd, node->data + node->data_pos, node->data_len);
@@ -986,15 +995,18 @@ cleanup_request(struct request *c)
if (event_initialized(&c->resp_ev))
event_del(&c->resp_ev);
if (event_initialized(&c->script_ev)) {
- close(EVENT_FD(&c->script_ev));
+ if (!c->stdout_fd_closed)
+ close(EVENT_FD(&c->script_ev));
event_del(&c->script_ev);
}
if (event_initialized(&c->script_err_ev)) {
- close(EVENT_FD(&c->script_err_ev));
+ if (!c->stderr_fd_closed)
+ close(EVENT_FD(&c->script_err_ev));
event_del(&c->script_err_ev);
}
if (event_initialized(&c->script_stdin_ev)) {
- close(EVENT_FD(&c->script_stdin_ev));
+ if (!c->stdin_fd_closed)
+ close(EVENT_FD(&c->script_stdin_ev));
event_del(&c->script_stdin_ev);
}
close(c->fd);