aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-10-12 19:41:33 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-10-12 19:41:33 +0200
commitb6d421b635670939e4ec047543f84cb507e5fe9d (patch)
treee8eda0cbd669c3e48ef97c4a2b41eaeeeb5ee546
parent122c47ac02e2d2f615b34fe744d958fcd245f3d5 (diff)
downloadbusybox-w32-b6d421b635670939e4ec047543f84cb507e5fe9d.tar.gz
busybox-w32-b6d421b635670939e4ec047543f84cb507e5fe9d.tar.bz2
busybox-w32-b6d421b635670939e4ec047543f84cb507e5fe9d.zip
telnetd: treat all 2-byte IACs in 240..249 range as NOPs.
A bit of future-proofing. Some of them can stand just being ignored. function old new delta telnetd_main 1791 1798 +7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/telnetd.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/networking/telnetd.c b/networking/telnetd.c
index 0da29410e..eaaf29bce 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -169,12 +169,10 @@ safe_write_to_pty_decode_iac(struct tsession *ts)
169 handle_iac: 169 handle_iac:
170 /* 2-byte commands (240..250 and 255): 170 /* 2-byte commands (240..250 and 255):
171 * IAC IAC (255) Literal 255. Supported. 171 * IAC IAC (255) Literal 255. Supported.
172 * IAC SE (240) End of subnegotiation. Treated as NOP.
172 * IAC NOP (241) NOP. Supported. 173 * IAC NOP (241) NOP. Supported.
173 * IAC BRK (243) Break. Like serial line break. TODO via tcsendbreak()? 174 * IAC BRK (243) Break. Like serial line break. TODO via tcsendbreak()?
174 * IAC AYT (246) Are you there. Send back evidence that AYT was seen. TODO (send NOP back)? 175 * IAC AYT (246) Are you there. Send back evidence that AYT was seen. TODO (send NOP back)?
175 * Implemented only as part of NAWS:
176 * IAC SB (250) Subnegotiation of an option follows.
177 * IAC SE (240) End of subnegotiation.
178 * These don't look useful: 176 * These don't look useful:
179 * IAC DM (242) Data mark. What is this? 177 * IAC DM (242) Data mark. What is this?
180 * IAC IP (244) Suspend, interrupt or abort the process. (Ancient cousin of ^C). 178 * IAC IP (244) Suspend, interrupt or abort the process. (Ancient cousin of ^C).
@@ -182,8 +180,11 @@ safe_write_to_pty_decode_iac(struct tsession *ts)
182 * IAC EC (247) Erase character. The receiver should delete the last received char. 180 * IAC EC (247) Erase character. The receiver should delete the last received char.
183 * IAC EL (248) Erase line. The receiver should delete everything up tp last newline. 181 * IAC EL (248) Erase line. The receiver should delete everything up tp last newline.
184 * IAC GA (249) Go ahead. For half-duplex lines: "now you talk". 182 * IAC GA (249) Go ahead. For half-duplex lines: "now you talk".
183 * Implemented only as part of NAWS:
184 * IAC SB (250) Subnegotiation of an option follows.
185 */ 185 */
186 if (buf[1] == IAC) { /* Literal 255 (emacs M-DEL) */ 186 if (buf[1] == IAC) {
187 /* Literal 255 (emacs M-DEL) */
187 //bb_error_msg("255!"); 188 //bb_error_msg("255!");
188 rc = safe_write(ts->ptyfd, &buf[1], 1); 189 rc = safe_write(ts->ptyfd, &buf[1], 1);
189 if (rc <= 0) 190 if (rc <= 0)
@@ -191,7 +192,9 @@ safe_write_to_pty_decode_iac(struct tsession *ts)
191 rc = 2; 192 rc = 2;
192 goto update_and_return; 193 goto update_and_return;
193 } 194 }
194 if (buf[1] == NOP) { /* NOP (241). Ignore (putty keepalive, etc) */ 195 if (buf[1] >= 240 && buf[1] <= 249) {
196 /* NOP (241). Ignore (putty keepalive, etc) */
197 /* All other 2-byte commands also treated as NOPs here */
195 rc = 2; 198 rc = 2;
196 goto update_and_return; 199 goto update_and_return;
197 } 200 }
@@ -205,24 +208,27 @@ safe_write_to_pty_decode_iac(struct tsession *ts)
205 goto update_and_return; 208 goto update_and_return;
206 } 209 }
207 210
208 /* TELOPT_NAWS support */ 211 if (buf[1] == SB) {
209 /* IAC SB, TELOPT_NAWS, 4-byte, IAC SE */ 212 if (buf[2] == TELOPT_NAWS) {
210 if (buf[1] == SB && buf[2] == TELOPT_NAWS) { 213 /* IAC SB, TELOPT_NAWS, 4-byte, IAC SE */
211 struct winsize ws; 214 struct winsize ws;
212 if (wr <= 8) { 215 if (wr <= 6) {
213/* BUG: incomplete, can't process */ 216/* BUG: incomplete, can't process */
214 rc = wr; 217 rc = wr;
218 goto update_and_return;
219 }
220 memset(&ws, 0, sizeof(ws)); /* pixel sizes are set to 0 */
221 ws.ws_col = (buf[3] << 8) | buf[4];
222 ws.ws_row = (buf[5] << 8) | buf[6];
223 ioctl(ts->ptyfd, TIOCSWINSZ, (char *)&ws);
224 rc = 7;
225 /* trailing IAC SE will be eaten separately, as 2-byte NOP */
215 goto update_and_return; 226 goto update_and_return;
216 } 227 }
217 memset(&ws, 0, sizeof(ws)); 228 /* else: other subnegs not supported yet */
218 ws.ws_col = (buf[3] << 8) | buf[4];
219 ws.ws_row = (buf[5] << 8) | buf[6];
220 ioctl(ts->ptyfd, TIOCSWINSZ, (char *)&ws);
221 rc = 9;
222 goto update_and_return;
223 } 229 }
224 230
225 /* Skip 3-byte cmds (assume they are WILL/WONT/DO/DONT 251..254 codes) */ 231 /* Assume it is a 3-byte WILL/WONT/DO/DONT 251..254 command and skip it */
226#if DEBUG 232#if DEBUG
227 fprintf(stderr, "Ignoring IAC %s,%s\n", 233 fprintf(stderr, "Ignoring IAC %s,%s\n",
228 TELCMD(buf[1]), TELOPT(buf[2])); 234 TELCMD(buf[1]), TELOPT(buf[2]));