telnetd: better AYT handling
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 4 Apr 2019 14:00:23 +0000 (16:00 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 4 Apr 2019 14:00:23 +0000 (16:00 +0200)
function                                             old     new   delta
telnetd_main                                        1792    1837     +45

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
networking/telnetd.c

index bd60c8681b8ffed0c0de6847cf878e59d8083b25..e94d3bd3d1ebdfeaa8c711cf098c61e196820787 100644 (file)
@@ -278,9 +278,14 @@ safe_write_to_pty_decode_iac(struct tsession *ts)
                goto update_and_return;
        }
        if (buf[1] == AYT) {
-               /* Send back evidence that AYT was seen. */
-               buf[1] = NOP;
-               /*rc =*/ safe_write(ts->sockfd_write, buf, 2);
+               if (ts->size2 == 0) { /* if nothing buffered yet... */
+                       /* Send back evidence that AYT was seen */
+                       unsigned char *buf2 = TS_BUF2(ts);
+                       buf2[0] = IAC;
+                       buf2[1] = NOP;
+                       ts->wridx2 = 0;
+                       ts->rdidx2 = ts->size2 = 2;
+                }
                rc = 2;
                goto update_and_return;
        }