Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Jul 2007 13:10:04 GMT
From:      Niclas Zeising <niclas.zeising@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/114498: [PATCH] bug in wall makes it skip characters
Message-ID:  <200707111310.l6BDA456079804@www.freebsd.org>
Resent-Message-ID: <200707111320.l6BDK2ht063286@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         114498
>Category:       bin
>Synopsis:       [PATCH] bug in wall makes it skip characters
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 11 13:20:02 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator:     Niclas Zeising
>Release:        7.0-CURRENT
>Organization:
N/A
>Environment:
N/A
>Description:
A bug in the makemsg() function in wall makes it skip one character when wrapping around the line to make a new one. It outputs character ... 78, 79, then cr-lf, then charcater 81, of what's inputed. The same goes for everytime it wraps a line, every 80th char is missing.  This is rather annoying since missing characters can give words completely new meanings and wall is used when shutting down etc.
>How-To-Repeat:
just run wall with a message longer than 80 caracters without a newline and see as one char is missing in the output.
>Fix:
Attached patch revrites the loop in makemsg() a little so to not skip any characters that shouldn't be skipped.  It also raises the warns level to 6 since wall seems to compile at warns 6, at least on i386... That part is not neccecary to include though.

Patch attached with submission follows:

diff -ur src/src/usr.bin/wall/Makefile src2/src/usr.bin/wall/Makefile
--- src/src/usr.bin/wall/Makefile	Fri May 27 14:33:28 1994
+++ src2/src/usr.bin/wall/Makefile	Tue Jul 10 17:20:55 2007
@@ -2,6 +2,7 @@
 
 PROG=	wall
 SRCS=	ttymsg.c wall.c
+WARNS=	6
 BINGRP=	tty
 BINMODE=2555
 
diff -ur src/src/usr.bin/wall/wall.c src2/src/usr.bin/wall/wall.c
--- src/src/usr.bin/wall/wall.c	Tue Feb 21 14:01:00 2006
+++ src2/src/usr.bin/wall/wall.c	Wed Jul 11 14:56:14 2007
@@ -193,10 +193,10 @@
 	exit(1);
 }
 
-void
+static void
 makemsg(char *fname)
 {
-	int cnt;
+	int cnt = 0;
 	unsigned char ch;
 	struct tm *lt;
 	struct passwd *pw;
@@ -251,12 +251,15 @@
 			err(1, "can't read %s", fname);
 		setegid(egid);
 	}
-	while (fgets(lbuf, sizeof(lbuf), stdin))
-		for (cnt = 0, p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) {
-			if (ch == '\r') {
+	while (fgets(lbuf, sizeof(lbuf), stdin)) {
+		p = lbuf;
+		/* Thos loop is pending rewrite */
+		while ((ch = *p++) != '\0') {
+		/* for (cnt = 0, p = lbuf; (ch = *p) != '\0'; p++, cnt++) { */
+			if (ch == '\r')
 				cnt = 0;
-			} else if (cnt == 79 || ch == '\n') {
-				for (; cnt < 79; ++cnt)
+			else if (ch == '\n') {
+				for(; cnt < 79; cnt++)
 					putc(' ', fp);
 				putc('\r', fp);
 				putc('\n', fp);
@@ -269,13 +272,13 @@
 				if (ch & 0x80) {
 					ch &= 0x7F;
 					putc('M', fp);
-					if (++cnt == 79) {
+					if (++cnt >= 79) {
 						putc('\r', fp);
 						putc('\n', fp);
 						cnt = 0;
 					}
 					putc('-', fp);
-					if (++cnt == 79) {
+					if (++cnt >= 79) {
 						putc('\r', fp);
 						putc('\n', fp);
 						cnt = 0;
@@ -284,17 +287,28 @@
 				if (iscntrl(ch)) {
 					ch ^= 040;
 					putc('^', fp);
-					if (++cnt == 79) {
+					if (++cnt >= 79) {
 						putc('\r', fp);
 						putc('\n', fp);
 						cnt = 0;
 					}
 				}
 				putc(ch, fp);
+				if (++cnt >= 79) {
+					putc('\r', fp);
+					putc('\n', fp);
+					cnt = 0;
+				}
 			} else {
 				putc(ch, fp);
+				if (++cnt >= 79) {
+					putc('\r', fp);
+					putc('\n', fp);
+					cnt = 0;
+				}
 			}
 		}
+	}
 	(void)fprintf(fp, "%79s\r\n", " ");
 	rewind(fp);
 


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707111310.l6BDA456079804>