If the telnet client switches to the character + local echo
mode (a non-standard combination) and it runs in a smart terminal
capable of doing echo, telnet client configures the terminal to
perform the echo. Telnet client itself does no echo.
There is a problem that telnet uses an incorrect combination of
flags, which causes End Of Line being displayed as "^M" instead
of performing CR+LF.
How to reproduce:
1. Run telnet client in a smart virtual terminal capable of local
echo (for example "xterm" or "gnome-terminal")
2. Connect to a telnetd capable and properly implementing WONT
ECHO.
3. Login to a shell that is capable to work in no echo mode:
- For example "bash --noediting" or call "set +o vi ;
set +o emacs" before changing telnet mode.
- You can also reproduce it with "cat" in place of login
shell.
4. Set the mode to the local echo using "send dont echo".
Now your telnet session should be in the character local echo
mode. (Character mode is the default and we did not change it
before switching to the local echo mode.)
Without the fix:
telnet> send dont echo
linux> #hello^Mlinux>
With the fix:
telnet> send dont echo
linux> #hello
linux>
Note: Characters "^M" are generated by mis-configured terminal on
the client side. They are not passed to the telnet
session. Telnet session correctly gets EOL (LF or CRLF).
Technical details:
Current implementation uses following set of flags:
onlcr -icrnl echo
In CRLF mode it first correctly sets
onlcr icrnl echo
but later in the code it changes flags to
onlcr -icrnl echo
The -icrnl causes echoing of control characters as "^{letter}",
including LF displayed as "^M".
According to Werner Fink <[email protected]>, this is a correct
behavior of terminal, just the combination of flags used is
incorrect.
However the problem was discovered on the Linux system, I
believe, that the problem is system independent, and affects all
systems. Attached patch seems to fix this issue without breaking
any other telnet modes.
Affected versions:
As OpenBSD seems to inherit the original BSD code, I am sending
this report here as well.
This problem probably exists from the very first implementation
of character echo mode in the BSD telnet (1987), and affects
probably all implementations derived from it:
- NetBSD telnet (the original code)
Reported there as http://gnats.netbsd.org/49392
- OpenBSD telnet (branched 1995 from NetBSD)
- netkit-telnet (now in Debian, branched between 1990 and 1993)
- telnet-bsd (Linux port from 1999 created by Thorsten Kukuk
<[email protected]>)
- FreeBSD telnet (significantly rewritten, branched between 1993
and 1997)
Proposed fix:
--- src/usr.bin/telnet/sys_bsd.c 2012-01-09 17:08:55.000000000 +0100
+++ src/usr.bin/telnet/sys_bsd.c 2014-11-14 21:24:49.540247131 +0100
@@ -355,7 +355,6 @@
tmp_tc.c_lflag |= ICANON;
} else {
tmp_tc.c_lflag &= ~ICANON;
- tmp_tc.c_iflag &= ~ICRNL;
tmp_tc.c_cc[VMIN] = 1;
tmp_tc.c_cc[VTIME] = 0;
}
(Internal SUSE bug reference: bnc#897696)
--
Stanislav Brabec
SUSE LINUX