[net.news.b] inews puts \377 into control messages

dmmartindale@watcgl.UUCP (Dave Martindale) (12/02/84)

There is code in insert() in inews.c that tries to compensate for the
now-infamous line-eater bug;  if an article begins with a blank or tab
an extra newline is added to the beginning of the body of the article.
Unfortunately, this code doesn't check for the case of a zero-length
article body - this is impossible for a normal article being posted,
but is always the case for some control messages (i.e. cancel).
So the code does a getc() which returns EOF into a char and later does a
putc of it into the article body, which results in a \377 character in
the article.  Normally this wouldn't bother anyone, but if you then
try to mail such an article body using the MMDF software, pmdf apparently
dies a horrible death.  Fixes to inews.c are as follows:

*** /tmp/inews.c	Sun Dec  2 13:46:43 1984
--- inews.c	Sun Dec  2 13:50:10 1984
***************
*** 504,510
  {
  	register char *ptr;
  	register FILE *tfp;
! 	char c;
  	struct srec srec;	/* struct for sys file lookup	*/
  	int is_invalid = FALSE;
  

--- 504,510 -----
  {
  	register char *ptr;
  	register FILE *tfp;
! 	register int c;
  	struct srec srec;	/* struct for sys file lookup	*/
  	int is_invalid = FALSE;
  
***************
*** 529,535
  
  	/* Write article to temp file. */
  	tfp = xfopen(mktemp(ARTICLE), "w");
! 	if ( (c=getc(infp)) == ' ' || c == '\t' ) {
  		header.intnumlines++;
  		sprintf(header.numlines,"%d",header.intnumlines);
  	}

--- 529,536 -----
  
  	/* Write article to temp file. */
  	tfp = xfopen(mktemp(ARTICLE), "w");
! 	/* part of kludge to get around article truncation problem */
! 	if ( (c=getc(infp)) != EOF && (c == ' ' || c == '\t') ) {
  		header.intnumlines++;
  		sprintf(header.numlines,"%d",header.intnumlines);
  	}
***************
*** 535,543
  	}
  	lhwrite(&header, tfp);
  	/* Kludge to get around article truncation problem */
! 	if (c == ' ' || c == '\t' )
! 		putc('\n', tfp);
! 	putc(c,tfp);
  	while (fgets(bfr, BUFLEN, infp) != NULL)
  		fputs(bfr, tfp);
  

--- 536,546 -----
  	}
  	lhwrite(&header, tfp);
  	/* Kludge to get around article truncation problem */
! 	if (c != EOF) {
! 		if (c == ' ' || c == '\t' )
! 			putc('\n', tfp);
! 		putc(c,tfp);
! 	}
  	while (fgets(bfr, BUFLEN, infp) != NULL)
  		fputs(bfr, tfp);
  

Even though the "while (fgets..." code could have been put inside the body
of the "if (c != EOF)" if statement, I left it out since the kludge should
one day be deleted, leaving just the while loop to copy the article body.

	Dave Martindale

dmmartindale@watcgl.UUCP (Dave Martindale) (12/03/84)

> So the code does a getc() which returns EOF into a char and later does a
> putc of it into the article body, which results in a \377 character in
> the article.

It is worth pointing out that if you have installed Larry Wall's patches
to inews that generate the Xref line, you have two copies of the code
which copies the article body.  One is in the spot I described in
my previous diff, and one is down at the bottom of insert().  One or
the other is compiled depending on whether DOXREFS is defined.
So there are two copies of the code that have to be fixed.

	Dave Martindale