From af278ac870c634f9f38b1ae2461b7ad580a4da1d Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 2 Feb 2021 18:19:56 +0000 Subject: [PATCH] Unix Plink: fix tight loop after EOF on stdin. When Plink saw EOF on stdin, it would continue to put stdin in its list of poll fds, so that the poll loop would always terminate instantly with stdin readable. Plink would read from it, see EOF again, go back to the poll loop, and keep spinning like that. This was supposed to be fixed by the 'sending' flag, which was set to false on seeing EOF to indicate that we were no longer interested in reading stdin data to send to the SSH server. But that flag was ineffective, because it turns out it was _always_ set to false - nothing in the code ever set it to true! And the reason why that didn't totally prevent reading from stdin at all is because it was also tested with the wrong sense. How embarrassing. Changed the flag name to 'seen_stdin_eof', and made it behave sensibly. --- unix/uxplink.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/unix/uxplink.c b/unix/uxplink.c index 0c573bf8..a698c010 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -572,13 +572,13 @@ const unsigned cmdline_tooltype = TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX | TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD; -static bool sending; +static bool seen_stdin_eof = false; static bool plink_pw_setup(void *vctx, pollwrapper *pw) { pollwrap_add_fd_rwx(pw, signalpipe[0], SELECT_R); - if (!sending && + if (!seen_stdin_eof && backend_connected(backend) && backend_sendok(backend) && backend_sendbuffer(backend) < MAX_STDIN_BACKLOG) { @@ -623,7 +623,7 @@ static void plink_pw_check(void *vctx, pollwrapper *pw) exit(1); } else if (ret == 0) { backend_special(backend, SS_EOF, 0); - sending = false; /* send nothing further after this */ + seen_stdin_eof = true; } else { if (local_tty) from_tty(buf, ret); @@ -948,7 +948,6 @@ int main(int argc, char **argv) local_tty = (tcgetattr(STDIN_FILENO, &orig_termios) == 0); atexit(cleanup_termios); seat_echoedit_update(plink_seat, 1, 1); - sending = false; cli_main_loop(plink_pw_setup, plink_pw_check, plink_continue, NULL);