Restoring block mode on exiting
David Newall
openssh at davidnewall.com
Fri Apr 23 12:44:41 AEST 2021
Hi Dmitry,
On 23/4/21 1:06 am, Dmitry Belyavskiy wrote:
> OpenSSH incorrectly restores the standard mode (blocking mode) on standard
> output upon exiting.
I agree that SSH should *restore* the blocking mode. I've only spent a
small
amount of timelooking at it and I think SSH currently does not do that, and
your patch also does not.
Your patch sets blocking mode if SSH cleared it. I think it would be more
correct to restore it tothe state that it was when SSH took over the file
because we shouldn't assume.
In channel_register_fds, don't record if we set non-blocking mode, record
what mode it currentlyhas:
c->nonblock = (get_nonblock(rfd) << 2) | (get_nonblock(wfd) << 1) |
get_nonblock(efd);
Restore in channel_close_fds:
channel_close_fd(ssh, &c->sock, 0);
if (rfd != sock) channel_close_fd(ssh, &c->rfd, c->nonblock & 4);
if (wfd != sock) channel_close_fd(ssh, &c->wfd, c->nonblock & 2);
if (efd != sock) channel_close_fd(ssh, &c->efd, c->nonblock & 1);
In channel_close_fd:
if (fd != -1) (nonblock?set_nonblock:unset_nonblock)(fd);
Regards,
David
More information about the openssh-unix-dev
mailing list