[net.news.b] Grab bag of bug fixes for news 2.10

rees@apollo.UUCP (Jim Rees) (12/30/83)

These are fixes to the bugs I found while porting news 2.10 to the
Apollo.  I have only included the fixes that I haven't seen elsewhere.
I have tried to test these fixes, but be aware that they haven't been
tested anywhere except here, so use the usual cautions installing them
at your site.

In caesar.c, there was a stack variable ("forced") used before it was
set, and a comparison of a char expression to EOF.

In control.c, some of the mailed back replies to control messages had
some incorrect headers.  I fixed them and generally cleaned up these
messages.

Routine type() in header.c would try to dereference a NULL pointer
if inews is handed a null message.

In inews.c, the log message for incorrect linecounts had an extra newline.

In pathinit.c, the file pointer for the NOTIFY file (in LIBDIR) never
got closed.

In readr.c there were some problems for newsgroups with no articles
in them.  You would probably only see this if you were bringing up
news on a new machine.  I also removed some unreachable debugging
print statements in the code that reads the spool directory after
not finding 5 articles in a row.  I don't think this code is part
of the standard distribution, and my apologies for forgetting who
wrote it.

The fixes follow.  As always, don't take the line numbers too seriously.

*** UW/caesar.c	Fri Aug 12 16:41:53 1983
--- caesar.c	Thu Oct  6 17:41:30 1983
***************
*** 41,47
  	int bufsize;
  	int c, i, try;
  	double dot, winnerdot;  /* .. */
! 	int winner, forced;
  	char *inbuf;
  
  	bufsize = 0;

--- 41,47 -----
  	int bufsize;
  	int c, i, try;
  	double dot, winnerdot;  /* .. */
! 	int winner, forced = 0;
  	char *inbuf;
  
  	bufsize = 0;
***************
*** 64,70
  
  		/* get a sample of the text */
  		for( i = 0; i < BUFSIZ; i++ ) {
! 			if( (inbuf[i] = c = getchar()) == EOF ) {
  				return;
  			}	
  			if (c == '\n') {

--- 64,70 -----
  
  		/* get a sample of the text */
  		for( i = 0; i < BUFSIZ; i++ ) {
! 			if( (c = getchar()) == EOF ) {
  				return;
  			}
  			inbuf[i] = c;
***************
*** 66,72
  		for( i = 0; i < BUFSIZ; i++ ) {
  			if( (inbuf[i] = c = getchar()) == EOF ) {
  				return;
! 			}	
  			if (c == '\n') {
  				bufsize = i+1; 
  				break;

--- 66,73 -----
  		for( i = 0; i < BUFSIZ; i++ ) {
  			if( (c = getchar()) == EOF ) {
  				return;
! 			}
! 			inbuf[i] = c;
  			if (c == '\n') {
  				bufsize = i+1; 
  				break;
*** UW/control.c	Fri Aug 12 16:41:58 1983
--- control.c	Sun Oct  9 19:48:58 1983
***************
*** 338,344
  		mclose(f);
  	}
  #endif
! 	f = mailhdr(&header, "Subject: response to your sendsys request\n\n");
  	u = fopen(SUBFILE, "r");
  	if (f != NULL && u != NULL) {
  		while ((c=getc(u)) != EOF)

--- 338,344 -----
  		mclose(f);
  	}
  #endif
! 	f = mailhdr(&header, "response to your sendsys request");
  	u = fopen(SUBFILE, "r");
  	if (f != NULL && u != NULL) {
  		putc('\n', f);
***************
*** 341,346
  	f = mailhdr(&header, "Subject: response to your sendsys request\n\n");
  	u = fopen(SUBFILE, "r");
  	if (f != NULL && u != NULL) {
  		while ((c=getc(u)) != EOF)
  			putc(c, f);
  		fclose(u);

--- 341,347 -----
  	f = mailhdr(&header, "response to your sendsys request");
  	u = fopen(SUBFILE, "r");
  	if (f != NULL && u != NULL) {
+ 		putc('\n', f);
  		while ((c=getc(u)) != EOF)
  			putc(c, f);
  		fclose(u);
***************
*** 407,413
  	if (f == NULL)
  		xerror("Cannot send back error message");
  	fprintf(f, "\nCurrently running news version %s.\n\n", news_version);
! 	fprintf(f, "The header of your message follows:\n");
  	hwrite(&header, f);
  	mclose(f);
  }

--- 424,430 -----
  	if (f == NULL)
  		xerror("Cannot send back error message");
  	fprintf(f, "\nCurrently running news version %s.\n\n", news_version);
! 	fprintf(f, "The header of your message follows:\n\n");
  	hwrite(&header, f);
  	mclose(f);
  }
***************
*** 425,432
  	f = mailhdr(h, "Unrecognized Control Message");
  	if (f == NULL)
  		xerror("Cannot send back error message");
! 	fprintf(f, "Currently running news B version %s.\n\n", news_version);
! 	fprintf(f, "The header of the message follows:\n");
  	hwrite(h, f);
  	mclose(f);
  }

--- 442,449 -----
  	f = mailhdr(h, "Unrecognized Control Message");
  	if (f == NULL)
  		xerror("Cannot send back error message");
! 	fprintf(f, "\nCurrently running news version %s.\n\n", news_version);
! 	fprintf(f, "The header of the message follows:\n\n");
  	hwrite(h, f);
  	mclose(f);
  }
***************
*** 440,447
  	f = mailhdr(&header, "Unimplemented Control Message");
  	if (f == NULL)
  		xerror("Cannot send back error message");
! 	fprintf(f, "Currently running news B version %s.\n\n", news_version);
! 	fprintf(f, "The header of the message follows:\n");
  	hwrite(&header, f);
  	mclose(f);
  }

--- 457,464 -----
  	f = mailhdr(&header, "Unimplemented Control Message");
  	if (f == NULL)
  		xerror("Cannot send back error message");
! 	fprintf(f, "\nCurrently running news version %s.\n\n", news_version);
! 	fprintf(f, "The header of the message follows:\n\n");
  	hwrite(&header, f);
  	mclose(f);
  }
*** UW/header.c	Tue Aug 16 16:02:50 1983
--- header.c	Fri Nov  4 14:38:27 1983
***************
*** 355,360
  {
  	char	*colon, *space;
  
  	if (!isalpha(*ptr) && strncmp(ptr, "From ", 5))
  		return FALSE;
  	colon = index(ptr, ':');

--- 352,359 -----
  {
  	char	*colon, *space;
  
+ 	if (ptr == NULL)
+ 		return FALSE;
  	if (!isalpha(*ptr) && strncmp(ptr, "From ", 5))
  		return FALSE;
  	colon = index(ptr, ':');
*** UW/inews.c	Fri Aug 12 16:42:19 1983
--- inews.c	Tue Oct 25 15:21:34 1983
***************
*** 711,717
  		 * line count.  But that seems a bit much for now.
  		 */
  		if (linecount != header.intnumlines)
! 			log("linecount expected %d, got %d\n", header.intnumlines, linecount);
  	} else {
  		/* Attach a line count to the article. */
  		header.intnumlines = linecount;

--- 812,818 -----
  		 * line count.  But that seems a bit much for now.
  		 */
  		if (linecount != header.intnumlines)
! 			log("linecount expected %d, got %d", header.intnumlines, linecount);
  	} else {
  		/* Attach a line count to the article. */
  		header.intnumlines = linecount;
*** UW/pathinit.c	Mon Oct 10 12:03:53 1983
--- pathinit.c	Fri Dec 16 09:51:37 1983
***************
*** 118,125
  	nfd = fopen(TELLFILE, "r");
  	if (nfd == NULL)
  		sprintf(TELLME, "%s", NOTIFY);
! 	else if (fscanf(nfd, "%s", TELLME) == EOF)
! 		strcpy(TELLME, "");
  # endif
  
  /*

--- 131,141 -----
  	nfd = fopen(TELLFILE, "r");
  	if (nfd == NULL)
  		sprintf(TELLME, "%s", NOTIFY);
! 	else {
! 		if (fscanf(nfd, "%s", TELLME) == EOF)
! 			strcpy(TELLME, "");
! 		fclose(nfd);
! 	}
  # endif
  
  /*
*** UW/readr.c	Fri Aug 12 16:43:35 1983
--- readr.c	Tue Oct 18 15:19:55 1983
***************
*** 988,994
  		bit = 1;
  
  	/* If done with this newsgroup, find the next one. */
! 	while (((long) bit > ngsize) || (rflag && bit < 1)) {
  		int i;
  		if (i=nextng()) {
  			if (actdirect == BACKWARD) {

--- 1054,1060 -----
  		bit = 1;
  
  	/* If done with this newsgroup, find the next one. */
! 	while (ngsize <= 0 || ((long) bit > ngsize) || (rflag && bit < 1)) {
  		int i;
  		if (i=nextng()) {
  			if (actdirect == BACKWARD) {
***************
*** 1040,1046
  	fprintf(stderr, "filename = '%s'\n", filename);
  #endif
  	/* Decide if we want to show this article. */
! 	if (access(filename, 4)) {
  		/* since there can be holes in legal article numbers, */
  		/* we wait till we hit 5 consecutive bad articles */
  		/* before we haul off and scan the directory */

--- 1106,1112 -----
  	fprintf(stderr, "filename = '%s'\n", filename);
  #endif
  	/* Decide if we want to show this article. */
! 	if (bit <= 0 || access(filename, 4)) {
  		/* since there can be holes in legal article numbers, */
  		/* we wait till we hit 5 consecutive bad articles */
  		/* before we haul off and scan the directory */
***************
*** 1046,1051
  		/* before we haul off and scan the directory */
  		if (++noaccess < 5)
  			goto badart;
  		fp = fopen(dirname(groupdir), "r");
  		if (fp == NULL) {
  #ifdef	DEBUG

--- 1112,1118 -----
  		/* before we haul off and scan the directory */
  		if (++noaccess < 5)
  			goto badart;
+ 		noaccess = 0;
  		fp = fopen(dirname(groupdir), "r");
  		if (fp == NULL) {
  #ifdef	DEBUG
***************
*** 1051,1057
  #ifdef	DEBUG
  	fprintf(stderr, "can't open groupdir (%s)\n", dirname(groupdir));
  #endif
- 			noaccess = 0;
  			goto badart;
  		}
  		nextnum = rflag ? 0 : ngsize;

--- 1118,1123 -----
  #ifdef	DEBUG
  	fprintf(stderr, "can't open groupdir (%s)\n", dirname(groupdir));
  #endif
  			goto badart;
  		}
  		nextnum = rflag ? 0 : ngsize;
***************
*** 1078,1086
  		abs = FALSE;
  		fclose(fp);
  		goto nextart;
- #ifdef	DEBUG
- 	fprintf(stderr, "bit %d nextnum %ld\n", bit, nextnum);
- #endif	DEBUG
  	} else
  		noaccess = 0;
  	if (ignorenews

--- 1144,1149 -----
  		abs = FALSE;
  		fclose(fp);
  		goto nextart;
  	} else
  		noaccess = 0;
  	if (ignorenews