NetBSD Problem Report #49392

From www@NetBSD.org  Fri Nov 14 20:37:59 2014
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 5CD3FA6685
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 14 Nov 2014 20:37:59 +0000 (UTC)
Message-Id: <20141114203757.D3916A66BB@mollari.NetBSD.org>
Date: Fri, 14 Nov 2014 20:37:57 +0000 (UTC)
From: sbrabec@suse.cz
Reply-To: sbrabec@suse.cz
To: gnats-bugs@NetBSD.org
Subject: telnet: bad terminal setup in character + local echo mode
X-Send-Pr-Version: www-1.0

>Number:         49392
>Category:       bin
>Synopsis:       telnet: bad terminal setup in character + local echo mode
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 14 20:40:00 +0000 2014
>Originator:     Stanislav Brabec
>Release:        CVS head
>Organization:
SUSE LINUX
>Environment:
not relevant
>Description:
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.

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 maintain the original BSD code, I am sending this report here.


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)
- 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  <kukuk@suse.de>)
- FreeBSD telnet (significantly rewritten, branched between 1993 and 1997)

(Internal SUSE bug reference: bnc#897696)
>How-To-Repeat:
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 properly implementing WONT ECHO.

3. Login to a shell that us 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).
>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;
     }

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.