Subject: bin/2684: rlogin passes wrong termianl speed; pass 960 if 9600.
To: None <gnats-bugs@NetBSD.ORG>
From: None <enami@ba2.so-net.or.jp>
List: netbsd-bugs
Date: 08/10/1996 21:51:22
>Number:         2684
>Category:       bin
>Synopsis:       rlogin passes wrong termianl speed; pass 960 if 9600.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Aug 10 09:05:01 1996
>Last-Modified:
>Originator:     enami tsugutomo
>Organization:
	I'm now at home
>Release:        1.2_BETA
>Environment:
System: NetBSD plants-doll.enami.ba2.so-net.or.jp 1.2_BETA NetBSD 1.2_BETA (PLANTS_DOLL) #180: Sat Jul 13 12:03:51 JST 1996 enami@plants-doll.enami.ba2.so-net.or.jp:/usr/src/sys/arch/i386/compile/PLANTS_DOLL i386
	(Don't worry, the kernel above is old but userland programs are
	up to date :).

>Description:
	If rlogin from NetBSD 1.2_BETA machine, tty speed passed to remote
	machine is wrong.  For example, when tty speed is 115200 on local
	machine, it become 11520 on remote machine.  If the remote machine
	is also NetBSD 1.2_BETA and do rlogin to another mahine, tty speed
	becomes 1152 on third mahine.

>How-To-Repeat:
	Just do rlogin and check terminal speed with stty.
>Fix:
	When passing tty speed, it was chaned to use snprintf but passed
	length doesn't includes trailing \0.  Actually, snprintf requires
	to include it.  Sample fix is appended.

enami.

Index: rlogin.c
===================================================================
RCS file: /a/cvsroot/NetBSD/usr.bin/rlogin/rlogin.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 rlogin.c
--- rlogin.c	1996/08/01 14:33:44	1.1.1.2
+++ rlogin.c	1996/08/10 12:45:35
@@ -268,11 +268,11 @@
 	}
 	len = strlen(term);
 	if (len < (sizeof(term) - 1) && tcgetattr(0, &tty) == 0) {
-		/* start at 2 to include the / */
-		for (ospeed = i = cfgetospeed(&tty), len2 = 2; i > 9; len2++)
+		/* start at 3 to include the leading / and trailing \0. */
+		for (ospeed = i = cfgetospeed(&tty), len2 = 3; i > 9; len2++)
 			i /= 10;
 
-		if (len + len2 < sizeof(term) - 1)
+		if (len + len2 < sizeof(term))
 			(void)snprintf(term + len, len2, "/%d", ospeed);
 	}
 
>Audit-Trail:
>Unformatted: