(Message inbox:629)
Received: from SAFE.Stanford.EDU by jessica.Stanford.EDU with TCP; Tue, 9 Aug 88 19:32:33 PDT
Received: from po2.andrew.cmu.edu ([128.2.249.105]) by safe.stanford.edu with Sendmail; Tue, 9 Aug 88 19:25:15 pdt
Received: by po2.andrew.cmu.edu (5.54/3.15) id <AA03689>; Tue, 9 Aug 88 21:47:41 EDT
Received: via switchmail for info-appletalk+@andrew.cmu.edu; Tue,  9 Aug 88 21:47:39 -0400 (EDT)
Received: from po3.andrew.cmu.edu via qmail
          ID </afs/andrew.cmu.edu/service/mailqs/q006/QF.po3.andrew.cmu.edu.22ffa9d0.91910a5>;
          Tue,  9 Aug 88 21:41:44 -0400 (EDT)
Received: by po3.andrew.cmu.edu (5.54/3.15) id <AA04249> for info-appletalk; Tue, 9 Aug 88 21:39:40 EDT
Received: by ucbvax.Berkeley.EDU (5.59/1.30)
	id AA13196; Tue, 9 Aug 88 17:46:57 PDT
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-appletalk@andrew.cmu.edu (info-appletalk@andrew.cmu.edu)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 10 Aug 88 00:21:57 GMT
From: budd@bu-cs.bu.edu  (Philip Budne)
Organization: Boston U. Comp. Sci.
Subject: Bug fix for aufs on Sun systems
Message-Id: <24348@bu-cs.BU.EDU>
Sender: info-appletalk-request@andrew.cmu.edu
To: info-appletalk@andrew.cmu.edu

Symptom:
	A bad "~user" in an afpvols file (user or guest) causes
	core dumps on a Sun.

	I previously reported a problem in logdir() to Charlie, (core
	dumps if -V references a nonexistant file) but never publicly
	posted the report or fix.

Problem:
	tilde passes NULL pointers to strcpy.

Cure:
	I have now made tilde and logdir more bulletproof as well as
	simplifying tilde, and adding an error check in VRdVFile.

================ in afpos.c

/*
 * char *tilde(char *s)
 *
 * Expands a path starting with tilde, the same as the shell.
 * Returns the expanded path.
 *
 */
export char *
tilde(s)
char *s;
{
  static char path[MAXPATHLEN];
  char *sp,*logdir(),*tp;
  
  if (*s != '~')			/* start with tilde? */
    return(s);				/* no, return original */
  s++;					/* skip over tilde */
  if ((sp = index(s,'/')) == NULL)	/* check for slash */
    return(logdir(s));			/*  return ~john expanded */

  *sp = '\0';				/* otherwise tie off ~bill/mac */
  if( (tp = logdir(s)) == NULL )	/* budd: try expansion */
    return( NULL );			/* budd: promulgate error! */
  strcpy(path,tp);			/* copy in the expanded ~bill */
  *sp = '/';				/* ... put back slash */
  strcat(path,sp);			/* append the remainder */
  return(path);				/* and return it */
}
  
export char *
logdir(user)
char *user;
{
  struct passwd *p;

  if (user == NULL || *user == '\0' ||	/* budd: NULL or empty user */
    (usrnam != NULL && strcmp(user,usrnam) == 0)) /* match stored user? */
    return(usrdir);		/* already know logged in user dir */
    
  p = (struct passwd *) getpwnam(user);
  if (p != NILPWD)
    return(p->pw_dir);
  return(NULL);
}

================ in afpvols.c

*** afpvols.c.1	Thu May 19 15:20:14 1988
--- afpvols.c	Fri Aug  5 12:34:48 1988
***************
*** 180,185 ****
--- 180,189 ----
      namep = p; p = vskip(p);		/* start of name */
      pswdp = p; p = vskip(p);		/* save it */
      pathp = tilde(pathp);		/* expand the path */
+     if (pathp == NULL) {		/* budd: if expansion failed */
+       log("VRdVFile: could not expand %s\n", line ); /* budd: whine */
+       continue;				/* budd: skip this one */
+     } /* ...budd */
      VNew(pathp,namep,pswdp);		/* add new entry */
    }
    fclose(fd);				/* close file */
