summaryrefslogtreecommitdiffstats
path: root/ssh.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@dtucker.net>2021-06-25 07:08:18 +0200
committerDarren Tucker <dtucker@dtucker.net>2021-06-25 07:08:18 +0200
commitc9f7bba2e6f70b7ac1f5ea190d890cb5162ce127 (patch)
treee19f873f052ae6a9e90b22311678e5dbe3592dbf /ssh.c
parentPut second -lssh in link line for sftp-server. (diff)
downloadopenssh-c9f7bba2e6f70b7ac1f5ea190d890cb5162ce127.tar.xz
openssh-c9f7bba2e6f70b7ac1f5ea190d890cb5162ce127.zip
Move closefrom() to before first malloc.
When built against tcmalloc, tcmalloc allocates a descriptor for its internal use, so calling closefrom() afterward causes the descriptor number to be reused resulting in a corrupted connection. Moving the closefrom a little earlier should resolve this. From kircherlike at outlook.com via bz#3321, ok djm@
Diffstat (limited to 'ssh.c')
-rw-r--r--ssh.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/ssh.c b/ssh.c
index cf8c018ec..0343cba32 100644
--- a/ssh.c
+++ b/ssh.c
@@ -653,6 +653,12 @@ main(int ac, char **av)
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
sanitise_stdfd();
+ /*
+ * Discard other fds that are hanging around. These can cause problem
+ * with backgrounded ssh processes started by ControlPersist.
+ */
+ closefrom(STDERR_FILENO + 1);
+
__progname = ssh_get_progname(av[0]);
#ifndef HAVE_SETPROCTITLE
@@ -668,12 +674,6 @@ main(int ac, char **av)
seed_rng();
- /*
- * Discard other fds that are hanging around. These can cause problem
- * with backgrounded ssh processes started by ControlPersist.
- */
- closefrom(STDERR_FILENO + 1);
-
/* Get user data. */
pw = getpwuid(getuid());
if (!pw) {