Bug 196902 - [PATCH] telnet: bad terminal setup in character + local echo mode
Summary: [PATCH] telnet: bad terminal setup in character + local echo mode
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2015-01-19 18:05 UTC by Stanislav Brabec
Modified: 2022-10-17 12:34 UTC (History)
0 users

See Also:


Attachments
Proposed fix (228 bytes, patch)
2015-01-19 18:05 UTC, Stanislav Brabec
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stanislav Brabec 2015-01-19 18:05:31 UTC
Created attachment 151861 [details]
Proposed fix

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 <werner@suse.com>, 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.

As FreeBSD 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)
  Reported as http://lists.openbsd.org/cgi-bin/mj_wwwusr?list=bugs&brief=on&func=archive-get-part&extra=201501/57 (browsing archives needs registration)
- netkit-telnet (now in Debian, branched between 1990 and 1993)
- telnet-bsd (Linux port from 1999 created by Thorsten Kukuk <kukuk@suse.de>)
- FreeBSD telnet (significantly rewritten, branched between 1993 and 1997)
Comment 1 Graham Perrin freebsd_committer freebsd_triage 2022-10-17 12:34:52 UTC
Keyword: 

    patch
or  patch-ready

– in lieu of summary line prefix: 

    [patch]

* bulk change for the keyword
* summary lines may be edited manually (not in bulk). 

Keyword descriptions and search interface: 

    <https://bugs.freebsd.org/bugzilla/describekeywords.cgi>