[comp.bugs.4bsd] msgs

page@ulowell.cs.ulowell.edu (Bob Page) (07/10/87)

Subject: msgs(1) doesn't filter garbage characters + FIX
Index:	/usr/src/ucb/msgs/msgs.c 4.3BSD

Description:
	Mail to msgs may contain non-printable characters which are
	not filtered upon delivery.  When reading the message, the
	non-printable characters are delivered to the output device.

Repeat-By:
	% echo ^V^G | mail -s "beep" msgs
	% msgs

	Sure, you might like control G and all the CSI stuff for
	blink and bold, but your system tyrants will love control S.

Fix:
	Apply this patch, which will filter the non-printable characters
	upon reading.  This isn't the best solution, but it's the one
	finger(1) uses, so I duplicated it.

*** msgs.c.orig	Thu Apr 10 12:20:43 1986
--- msgs.c	Fri Jul 10 16:10:08 1987
***************
*** 464,470 ****
  			while (nlines < 6
  			    && fgets(inbuf, sizeof inbuf, newmsg)
  			    && inbuf[0] != '\n') {
! 				fputs(inbuf, stdout);
  				nlines++;
  			}
  		}
--- 464,481 ----
  			while (nlines < 6
  			    && fgets(inbuf, sizeof inbuf, newmsg)
  			    && inbuf[0] != '\n') {
! 			        register i = 0;
! 				for (;;) {
! 				        register char c = inbuf[i++];
! 					if (c == '\n') {
! 					        putchar(c);
! 						break;
! 					}
! 					if (isprint(c) || isspace(c))
! 						putchar(c);
! 					else
! 						putchar(c ^ 100);
! 				}
  				nlines++;
  			}
  		}
***************
*** 590,596 ****
  		putc('\n', outf);
  
  	while (fgets(inbuf, sizeof inbuf, newmsg)) {
! 		fputs(inbuf, outf);
  		if (ferror(outf)) {
  			clearerr(outf);
  			break;
--- 601,618 ----
  		putc('\n', outf);
  
  	while (fgets(inbuf, sizeof inbuf, newmsg)) {
! 	        register i = 0;
! 		for (;;) {
! 		        register char c = inbuf[i++];
! 			if (c == '\n') {
! 			        putc(c, outf);
! 				break;
! 			}
! 			if (isprint(c) || isspace(c))
! 				putc(c, outf);
! 			else
! 				putc(c ^ 100, outf);
! 		}
  		if (ferror(outf)) {
  			clearerr(outf);
  			break;
-- 
Bob Page, U of Lowell CS Dept.   page@ulowell.{uucp,edu,csnet} 

matt@oddjob.UChicago.EDU (Matt Crawford) (07/11/87)

page@ulowell.cs.ulowell.edu (Bob Page) writes:
) Subject: msgs(1) doesn't filter garbage characters + FIX
) Index:	/usr/src/ucb/msgs/msgs.c 4.3BSD
) ...

Unfortunately this fix propagates a bug in the 4.3 finger
program.  Change all instances of "c ^ 100" to "c ^ 0100".

			Matt Crawford
	I can incant, decant and recant, but I can't cant.