From nobody@FreeBSD.org  Wed Jul 11 13:10:05 2007
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 585D316A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 11 Jul 2007 13:10:05 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [69.147.83.33])
	by mx1.freebsd.org (Postfix) with ESMTP id 3CC6013C44B
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 11 Jul 2007 13:10:05 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l6BDA4E5079807
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 11 Jul 2007 13:10:05 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id l6BDA456079804;
	Wed, 11 Jul 2007 13:10:04 GMT
	(envelope-from nobody)
Message-Id: <200707111310.l6BDA456079804@www.freebsd.org>
Date: Wed, 11 Jul 2007 13:10:04 GMT
From: Niclas Zeising <niclas.zeising@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] bug in wall makes it skip characters
X-Send-Pr-Version: www-3.0

>Number:         114498
>Category:       bin
>Synopsis:       [PATCH] bug in wall(1) makes it skip characters
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    das
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 11 13:20:02 GMT 2007
>Closed-Date:    Tue Jan 15 07:41:01 UTC 2008
>Last-Modified:  Tue Jan 15 07:50:01 UTC 2008
>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:
 
From: Niclas Zeising <niclas.zeising@gmail.com>
To: FreeBSD-gnats-submit@FreeBSD.org,  freebsd-bugs@FreeBSD.org
Cc:  
Subject: Re: bin/114498: [PATCH] bug in wall makes it skip characters
Date: Wed, 11 Jul 2007 20:45:52 +0200
 
 After reviewing the patch i noticed I had forgotten to remove two 
 comments I kept during the rewrite, so I've made a new patch.  The patch 
 is only for wall.c, Makefile is fine as it is in the patch.
 Regards!
 //Niclas
 
 --- patch.diff begins here ---
  --- src/usr.bin/wall/wall.c.orig	2007-07-11 20:40:25.000000000 +0200
  +++ src/usr.bin/wall/wall.c	2007-07-11 17:33:23.000000000 +0200
  @@ -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,14 @@
   			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;
  +		while ((ch = *p++) != '\0') {
  +			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 +271,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 +286,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);
   
 --- patch.diff ends here ---
Responsible-Changed-From-To: freebsd-bugs->das 
Responsible-Changed-By: das 
Responsible-Changed-When: Tue Jan 15 07:39:49 UTC 2008 
Responsible-Changed-Why:  
Over to me. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=114498 
State-Changed-From-To: open->closed 
State-Changed-By: das 
State-Changed-When: Tue Jan 15 07:40:31 UTC 2008 
State-Changed-Why:  
Committed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=114498 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/114498: commit references a PR
Date: Tue, 15 Jan 2008 07:40:37 +0000 (UTC)

 das         2008-01-15 07:40:30 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.bin/wall         wall.c 
   Log:
   Fix some bugs in wall(1):
   - Handle wrapping correctly when \r appears in the input, and don't
     remove the \r from the output.
   - For lines longer than 79 characters, don't drop every 80th character.
   - Style: Braces around compound while statement.
   
   PR:             114498
   Submitted by:   Niclas Zeising <niclas.zeising@gmail.com> (earlier version)
   
   Revision  Changes    Path
   1.25      +13 -6     src/usr.bin/wall/wall.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
