Bug 2797 - ssh swallows end-of-file on output
Summary: ssh swallows end-of-file on output
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh (show other bugs)
Version: 7.6p1
Hardware: All All
: P5 normal
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks: V_7_7
  Show dependency treegraph
 
Reported: 2017-10-23 07:21 AEDT by David Newall
Modified: 2018-05-28 20:04 AEST (History)
2 users (show)

See Also:


Attachments
transfer stdout to channel (1.01 KB, patch)
2017-10-23 10:04 AEDT, Damien Miller
no flags Details | Diff
attempt 2 - delay clobbering of stdout until after LocalCommand (1.05 KB, patch)
2017-10-23 11:02 AEDT, Damien Miller
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Newall 2017-10-23 07:21:13 AEDT
Ssh duplicates FILENO_STDOUT and FILENO_STDERR, thus there are two descriptors for each of those files.  When the remote program closes its stdout or stderr, the remote sshd sends the appropriate message to the local ssh which responds by closing the duplicate descriptor, but the original descriptor remains open.  A program reading from ssh's stdout (or stderr) cannot tell that the remote program has closed the file.

This is what should happen:

$ sh -c 'exec cat >&- 2>&-; sleep 5' | { read s || echo eof; }
eof
[then 5 second pause]

This is what happens using ssh:

$ ssh localhost 'exec >&- 2>&-; sleep 5' | { read s || echo eof; }
[5 second pause]
eof
Comment 1 Damien Miller 2017-10-23 10:04:32 AEDT
Created attachment 3073 [details]
transfer stdout to channel

This transfers ownership of stdout to the session channel, clobbering the original STDOUT_FILENO with /dev/null to ensure that nothing writes to it after any subsequent fds are opened, since they could be allocated fd=1.
Comment 2 Damien Miller 2017-10-23 11:02:54 AEDT
Created attachment 3074 [details]
attempt 2 - delay clobbering of stdout until after LocalCommand

Previous patch was incorrect - LocalCommand may write to stdout, so delay clobbering STDOUT_FILENO until it has completed.
Comment 3 Damien Miller 2017-10-23 21:48:59 AEDT
Hang on - the patch isn't committed yet!
Comment 4 Damien Miller 2017-10-25 13:24:24 AEDT
Patch has been committed and will be in openssh-7.7
Comment 5 Damien Miller 2018-04-06 12:26:41 AEST
Close all resolved bugs after release of OpenSSH 7.7.