From 709e7f6d4fbca1018ba06b1e2259cc708a4c9cee Mon Sep 17 00:00:00 2001 From: florian Date: Mon, 21 Oct 2013 18:19:27 +0000 Subject: Do not leak fds in fork(2) error path. pointed out by deraadt@ --- slowcgi.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'slowcgi.c') diff --git a/slowcgi.c b/slowcgi.c index a0c0aec..1a0b819 100644 --- a/slowcgi.c +++ b/slowcgi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: slowcgi.c,v 1.22 2013/10/21 18:17:58 florian Exp $ */ +/* $OpenBSD: slowcgi.c,v 1.23 2013/10/21 18:19:27 florian Exp $ */ /* * Copyright (c) 2013 David Gwynne * Copyright (c) 2013 Florian Obser @@ -827,7 +827,23 @@ exec_cgi(struct request *c) switch (pid = fork()) { case -1: + c->script_status = errno; + lwarn("fork"); + + close(s_in[0]); + close(s_out[0]); + close(s_err[0]); + + close(s_in[1]); + close(s_out[1]); + close(s_err[1]); + + c->stdin_fd_closed = c->stdout_fd_closed = + c->stderr_fd_closed = 1; + c->script_flags = (STDOUT_DONE | STDERR_DONE | SCRIPT_DONE); + + create_end_record(c); return; case 0: /* Child process */ -- cgit v1.2.3-2-gb3c3