[comp.protocols.appletalk] CAP Patch to resolve a bug in lwsrv

liam@cs.qmw.ac.uk (William Roberts) (08/09/90)

In a patch which I mailed out some while ago, I fixed a bug in
applications/lwsrv/procset.c which caused the lwsrv to loop
indefinitely, filling up your disk with logfiles.

However, not being able to leave well alone, that patch also fixed
the stupid behaviour of dictselect, which applied a sanity check
only to files called ".foo" and similar, but otherwise passed all
names through unexamined.

Little did I suspect that this would uncover a more important bug
elsewhere in procset.c: the dictselect function is being applied
BEFORE the chdir to the appropriate directory, so the files now all fail to
stat because the program isn't looking for them in the right place.

Symptom: lwsrv never recognises any of the files in the AppleDicts
         directory.
Fix:     Move the if(chdir(dfn) <0) { ... } code BEFORE the scandir.

Here is a context diff between the original file as distributed by
Rutgers, and the twice fixed procset.c (i.e. this one has the
fix for not looping madly, and the *complete* fix for a sensible
checking of files in the AppleDict directory). 

Feel free to mail me if you want to be sent the whole file as a replacement.


*** /tmp/,RCSt1a02075	Wed Aug  8 14:37:38 1990
--- procset.c	Wed Aug  8 14:34:27 1990
***************
*** 1,6 ****
! static char rcsid[] = "$Author: root $ $Date: 90/06/18 12:04:10 $";
! static char rcsident[] = "$Header: procset.c,v 1.1 90/06/18 12:04:10 root Exp $";
! static char revision[] = "$Revision: 1.1 $";
  
  /*
   * procset - UNIX AppleTalk spooling program: act as a laserwriter
--- 1,6 ----
! static char rcsid[] = "$Author: root $ $Date: 90/08/08 14:34:56 $";
! static char rcsident[] = "$Header: procset.c,v 1.2 90/08/08 14:34:56 root Locked $";
! static char revision[] = "$Revision: 1.2 $";
  
  /*
   * procset - UNIX AppleTalk spooling program: act as a laserwriter
***************
*** 24,32 ****
  #include <sys/file.h>
  #include <sys/dir.h>
  #include <sys/stat.h>
- #ifdef pyr
- #define ntohs(x) (x)
- #endif
  #include <netat/appletalk.h>
  #include <netat/sysvcompat.h>
  #include <netat/compat.h>
--- 24,29 ----
***************
*** 83,96 ****
  dictselect(d)
  struct direct *d;
  {
! 
!   if (d->d_name[0] != '.')
!     return(TRUE);
!   if (d->d_name[1] == '\0')		/* exclude "." */
!     return(FALSE);
!   if (d->d_name[1] == '.' && d->d_name[2] == '\0') /* exclude ".." */
!     return(FALSE);
!   return(checkfile(d->d_name));
  }
  
  /*
--- 80,86 ----
  dictselect(d)
  struct direct *d;
  {
!   return checkfile(d->d_name);
  }
  
  /*
***************
*** 129,139 ****
      return;
    }
  #endif
-   if ((nlst = scandir(dfn, &namelist, dictselect, NULL)) < 0) {
-     perror(dfn);
-     fprintf(stderr, "Can't find dictionary files!\n");
-     return;
-   }
    if (chdir(dfn) < 0) {
      perror("chdir");
      fprintf(stderr, "on path %s\n",dfn);
--- 119,124 ----
***************
*** 140,145 ****
--- 125,135 ----
      (void)chdir(path);                  /* try to go back in case... */
      return;
    }
+   if ((nlst = scandir(".", &namelist, dictselect, NULL)) < 0) {
+     perror(dfn);
+     fprintf(stderr, "Can't find dictionary files!\n");
+     return;
+   }
    for (i = 0, dp = namelist[0]; i < nlst ; i++, dp = namelist[i]) {
      if ((fp = fopen(dp->d_name, "r")) == NULL)
        goto baddict;
***************
*** 170,180 ****
      } else {
        if ((dl = (DictList *)malloc(sizeof(DictList))) == NULL)
  	goto baddict;
      }
      dl->ad_ver = strdup(psn);		/* remember proc set name */
      dl->ad_fn = strdup(dp->d_name);	/* remember file name */
-     dl->ad_next = dicthead;		/* link into list */
-     dicthead = dl;
  baddict:
      free(dp);
    }
--- 160,169 ----
      } else {
        if ((dl = (DictList *)malloc(sizeof(DictList))) == NULL)
  	goto baddict;
+       newdictionary(dl);        /* link into list */
      }
      dl->ad_ver = strdup(psn);           /* remember proc set name */
      dl->ad_fn = strdup(dp->d_name);     /* remember file name */
  baddict:
      free(dp);
    }
-- 

William Roberts                 ARPA: liam@cs.qmw.ac.uk
Queen Mary & Westfield College  UUCP: liam@qmw-cs.UUCP
Mile End Road                   AppleLink: UK0087
LONDON, E1 4NS, UK              Tel:  071-975 5250 (Fax: 081-980 6533)