From 7be4ac813662f68e89f23c50de058a49aa32f7e4 Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Wed, 19 May 2021 01:24:05 +0000 Subject: upstream: restore blocking status on stdio fds before close ssh(1) needs to set file descriptors to non-blocking mode to operate but it was not restoring the original state on exit. This could cause problems with fds shared with other programs via the shell, e.g. > $ cat > test.sh << _EOF > #!/bin/sh > { > ssh -Fnone -oLogLevel=verbose ::1 hostname > cat /usr/share/dict/words > } | sleep 10 > _EOF > $ ./test.sh > Authenticated to ::1 ([::1]:22). > Transferred: sent 2352, received 2928 bytes, in 0.1 seconds > Bytes per second: sent 44338.9, received 55197.4 > cat: stdout: Resource temporarily unavailable This restores the blocking status for fds 0,1,2 (stdio) before ssh(1) abandons/closes them. This was reported as bz3280 and GHPR246; ok dtucker@ OpenBSD-Commit-ID: 8cc67346f05aa85a598bddf2383fcfcc3aae61ce --- clientloop.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'clientloop.c') diff --git a/clientloop.c b/clientloop.c index 219f0e904..bdd676867 100644 --- a/clientloop.c +++ b/clientloop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clientloop.c,v 1.362 2021/05/04 22:53:52 dtucker Exp $ */ +/* $OpenBSD: clientloop.c,v 1.363 2021/05/19 01:24:05 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -1405,14 +1405,6 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg, if (have_pty) leave_raw_mode(options.request_tty == REQUEST_TTY_FORCE); - /* restore blocking io */ - if (!isatty(fileno(stdin))) - unset_nonblock(fileno(stdin)); - if (!isatty(fileno(stdout))) - unset_nonblock(fileno(stdout)); - if (!isatty(fileno(stderr))) - unset_nonblock(fileno(stderr)); - /* * If there was no shell or command requested, there will be no remote * exit status to be returned. In that case, clear error code if the -- cgit v1.2.3