From d84df989db48f76be16c34f7795e6788ee7841bc Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Thu, 6 Dec 2001 16:35:40 +0000 Subject: - markus@cvs.openbsd.org 2001/11/19 11:20:21 [sshd.c] fd leak on HUP; ok stevesk@ --- sshd.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'sshd.c') diff --git a/sshd.c b/sshd.c index f81597f1d..dc4f52322 100644 --- a/sshd.c +++ b/sshd.c @@ -40,7 +40,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: sshd.c,v 1.210 2001/11/14 20:45:08 deraadt Exp $"); +RCSID("$OpenBSD: sshd.c,v 1.211 2001/11/19 11:20:21 markus Exp $"); #include #include @@ -185,6 +185,10 @@ int session_id2_len = 0; /* record remote hostname or ip */ u_int utmp_len = MAXHOSTNAMELEN; +/* options.max_startup sized array of fd ints */ +int *startup_pipes = NULL; +int startup_pipe; /* in child */ + /* Prototypes for various functions defined later in this file. */ void destroy_sensitive_data(void); @@ -203,6 +207,16 @@ close_listen_socks(void) num_listen_socks = -1; } +static void +close_startup_pipes(void) +{ + int i; + if (startup_pipes) + for (i = 0; i < options.max_startups; i++) + if (startup_pipes[i] != -1) + close(startup_pipes[i]); +} + /* * Signal handler for SIGHUP. Sshd execs itself when it receives SIGHUP; * the effect is to reread the configuration file (and to regenerate @@ -227,6 +241,7 @@ sighup_restart(void) { log("Received SIGHUP; restarting."); close_listen_socks(); + close_startup_pipes(); execv(saved_argv[0], saved_argv); log("RESTART FAILED: av[0]='%.100s', error: %.100s.", saved_argv[0], strerror(errno)); exit(1); @@ -528,9 +543,6 @@ drop_connection(int startups) return (r < p) ? 1 : 0; } -int *startup_pipes = NULL; /* options.max_startup sized array of fd ints */ -int startup_pipe; /* in child */ - /* * Main program for the daemon. */ @@ -1058,9 +1070,7 @@ main(int ac, char **av) * the connection. */ startup_pipe = startup_p[1]; - for (j = 0; j < options.max_startups; j++) - if (startup_pipes[j] != -1) - close(startup_pipes[j]); + close_startup_pipes(); close_listen_socks(); sock_in = newsock; sock_out = newsock; -- cgit v1.2.3