[comp.sources.d] C News production release bugs

geoff@utstat.uucp (Geoff Collyer) (06/13/89)

Disclaimer: Henry and I do not subscribe to the patch-of-the-day club.
We are even less happy about software whose patches precede it.
However, the following bugs, all involving control messages, need
fixing.  We know of no other bugs in the production release.

These fixes will appear in the comp.sources.unix distribution, to
appear after Usenix.  Sites making C news available for uucp, ftp,
etc.  are asked to update their C news distributions (often just
cnews.Z).  The old cnews.Z was 380319 bytes; the new one is 380755
bytes.  The updated distribution can be retrieved from:
utzoo!~/dtr/cnews.Z, utgpu!/usr/spool/uucppublic/cnews.Z, and
uunet!~/news/cnews.Z by uucp, also known as
uunet.uu.net:~ftp/news/cnews.Z by ftp.  The copy on neat.ai.toronto.edu
for ftp will be updated when neat.ai comes up after its latest
disastrous crash.  The copy on radio.astro.toronto.edu for ftp should
be updated soon.

1. relay/mkpdir couldn't invoke itself because it was not found by its
own PATH.  Jean-Francois Lamy reported this one.

2. relaynews dumped core from not invalidating the last-newsgroup cache
in active.c.  This was found thanks to Mark Moraes's malloc.

3. control messages always got the default environment variables, even
on a test system, because control.c used standard() to clear the
environment.  Now it uses closeall(1) instead since PATH and IFS are
set at start up.

The plain diffs are just 34 lines in total; they appear first and
equivalent context diffs follow them.


--- relay/aux/mkpdir ---
7c7
< PATH=$NEWSCTL/bin:$NEWSBIN:$NEWSPATH ; export PATH	# must include this file's dir.
---
> PATH=$NEWSCTL/bin:$NEWSBIN/relay:$NEWSBIN:$NEWSPATH ; export PATH	# must include this file's dir.
--- relay/control.c ---
173,174c173,174
<  * Enforce at least minimal security: standardise the environment,
<  * including PATH and IFS using standard(), a local addition to libc;
---
>  * Enforce at least minimal security: the environment was standardised at
>  * startup, including PATH and IFS; close non-standard file descriptors;
184c184
< 	standard();				/* close most files, etc. */
---
> 	closeall(1);
--- relay/active.c ---
36a37,40
> static struct lastngcache {
> 	char *lnc_ng;			/* newsgroup name */
> 	char *lnc_line;			/* matching active file line */
> } lnc = { NULL, NULL };
50,53d53
< 	static struct lastngcache {
< 		char *lnc_ng;		/* newsgroup name */
< 		char *lnc_line;		/* matching active file line */
< 	} lnc = { NULL, NULL };
135c135,136
<  * Write back to disk the active file cache, if any.
---
>  * Write back to disk the active file cache, if any, and flush the
>  * last-newsgroup-cache, since it refers to the (now invalid) active file cache.
142a144
> 		lnc.lnc_ng = lnc.lnc_line = NULL;



*** relay/active.c.old	Mon Jun 12 04:12:47 1989
--- relay/active.c	Mon Jun 12 04:12:49 1989
***************
*** 34,39
  char actrelnm[] = "active";
  
  static FILE *actfp = NULL;
  
  /*
   * return a pointer to the active file entry for ng

--- 34,43 -----
  char actrelnm[] = "active";
  
  static FILE *actfp = NULL;
+ static struct lastngcache {
+ 	char *lnc_ng;			/* newsgroup name */
+ 	char *lnc_line;			/* matching active file line */
+ } lnc = { NULL, NULL };
  
  /*
   * return a pointer to the active file entry for ng
***************
*** 47,56
  {
  	register char *ngline, *ng, *flag;
  	register int loopbreak = 100;
- 	static struct lastngcache {
- 		char *lnc_ng;		/* newsgroup name */
- 		char *lnc_line;		/* matching active file line */
- 	} lnc = { NULL, NULL };
  
  	if (lnc.lnc_ng != NULL && STREQ(lnc.lnc_ng, ang))
  		return lnc.lnc_line;

--- 51,56 -----
  {
  	register char *ngline, *ng, *flag;
  	register int loopbreak = 100;
  
  	if (lnc.lnc_ng != NULL && STREQ(lnc.lnc_ng, ang))
  		return lnc.lnc_line;
***************
*** 132,138
  }
  
  /*
!  * Write back to disk the active file cache, if any.
   */
  statust
  actsync()

--- 132,139 -----
  }
  
  /*
!  * Write back to disk the active file cache, if any, and flush the
!  * last-newsgroup-cache, since it refers to the (now invalid) active file cache.
   */
  statust
  actsync()
***************
*** 140,145
  	register statust status = ST_OKAY;
  
  	if (actfp != NULL) {
  		status |= actfsync(actfp);
  		if (nfclose(actfp) == EOF || status != ST_OKAY) {
  			warning("error writing `%s'", ctlfile(actrelnm));

--- 141,147 -----
  	register statust status = ST_OKAY;
  
  	if (actfp != NULL) {
+ 		lnc.lnc_ng = lnc.lnc_line = NULL;
  		status |= actfsync(actfp);
  		if (nfclose(actfp) == EOF || status != ST_OKAY) {
  			warning("error writing `%s'", ctlfile(actrelnm));


*** relay/control.c.old	Mon Jun 12 05:08:34 1989
--- relay/control.c	Mon Jun 12 05:08:34 1989
***************
*** 170,177
   * runctlmsg is called from a child of relaynews, so it must always
   * call _exit() rather than exit() to avoid flushing stdio buffers.
   *
!  * Enforce at least minimal security: standardise the environment,
!  * including PATH and IFS using standard(), a local addition to libc;
   * reject shell metacharacters in ctlcmd.
   */
  STATIC void

--- 170,177 -----
   * runctlmsg is called from a child of relaynews, so it must always
   * call _exit() rather than exit() to avoid flushing stdio buffers.
   *
!  * Enforce at least minimal security: the environment was standardised at
!  * startup, including PATH and IFS; close non-standard file descriptors;
   * reject shell metacharacters in ctlcmd.
   */
  STATIC void
***************
*** 181,187
  	register char *cmd;
  	register int cmdstat;
  
! 	standard();				/* close most files, etc. */
  	if (!safecmd(ctlcmd)) {
  		(void) fprintf(stderr,
  		    "%s: control `%s' looks unsafe to execute\n", progname, ctlcmd);

--- 181,187 -----
  	register char *cmd;
  	register int cmdstat;
  
! 	closeall(1);
  	if (!safecmd(ctlcmd)) {
  		(void) fprintf(stderr,
  		    "%s: control `%s' looks unsafe to execute\n", progname, ctlcmd);


*** relay/aux/mkpdir.old	Mon Jun 12 21:07:27 1989
--- relay/aux/mkpdir	Mon Jun 12 21:07:28 1989
***************
*** 4,10
  # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  . ${NEWSCONFIG-/usr/lib/news/bin/config}
  export NEWSCTL NEWSBIN NEWSARTS
! PATH=$NEWSCTL/bin:$NEWSBIN:$NEWSPATH ; export PATH	# must include this file's dir.
  
  umask $NEWSUMASK
  

--- 4,10 -----
  # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  . ${NEWSCONFIG-/usr/lib/news/bin/config}
  export NEWSCTL NEWSBIN NEWSARTS
! PATH=$NEWSCTL/bin:$NEWSBIN/relay:$NEWSBIN:$NEWSPATH ; export PATH	# must include this file's dir.
  
  umask $NEWSUMASK
  
-- 
Geoff Collyer		utzoo!utstat!geoff, geoff@utstat.toronto.edu
``... skill such as yours is evidence of a misspent youth.'' - Herbert Spencer

jbuck@epimass.EPI.COM (Joe Buck) (06/14/89)

In article <1989Jun13.034954.144@utstat.uucp> geoff@utstat.uucp (Geoff Collyer) writes:
>Disclaimer: Henry and I do not subscribe to the patch-of-the-day club.
>We are even less happy about software whose patches precede it.
>However, the following bugs, all involving control messages, need
>fixing.  We know of no other bugs in the production release.

Geoff, if you were a member of the patch-of-the-day club, you would
know how to issue a patch.  The patch you post does not change any
version numbers or strings, does not modify a "patchlevel" file, or
anything of the sort.  It will be extremely difficult for people to
ascertain which version of C news they have if you persist in handling
bug fixes in this fashion; we'll be back to the bad old days of 2.10.2
news with a different set of local hacks on every system on the net.

Please, for the sake of your own reputation, be more careful in the
future as to how you distribute patches.  Larry Wall's system actually
does work; he successfully got the net as a whole to apply 40 (count
'em, 40) patches to rn and the sucker actually works, because there
are version strings and a patchlevel file and other stuff that lets
you have confidence that the patch was done right.
-- 
-- Joe Buck	jbuck@epimass.epi.com, uunet!epimass.epi.com!jbuck