A fix to the w.c bug fix (sigh)

utzoo!decvax!pur-ee!purdue!pur-phy!crl utzoo!decvax!pur-ee!purdue!pur-phy!crl
Mon Mar 29 13:27:45 AEST 1982


Well, I guess I spoke too soon with my previous bug fix.  There's a 
problem that I didn't notice before. This occurs when someone is logged
on has an 8-character user name.  Because most of the users around
here have short id's, I missed this point in testing.  The entry in
utmp is not guaranteed to be null-terminated, so the call to getpwnam()
returns NULL when that happens.  The fix is indicated below.
Also, if you haven't done so already, it is really advantageous to make
w be setuid to root so that it can use the phys() system call (if you
have it).  This reduces system time used by about 5 sec.

Charles LaBrec
pur-ee!physics:crl

----------------------------------------
*** w.c.old	Mon Mar 29 13:11:10 1982
--- w.c		Mon Mar 29 13:14:11 1982
***************
*** 108,114
  {
  	int days, hrs, mins;
  	register int i, j;
! 	char *cp;
  	register int curpid, empty;
  	struct passwd *pwptr;
  

--- 108,114 -----
  {
  	int days, hrs, mins;
  	register int i, j;
! 	char *cp, tmp[9];
  	register int curpid, empty;
  	struct passwd *pwptr;
  
***************
*** 235,241
  		}
  		if (utmp.ut_name[0] == '\0')
  			continue;	/* that tty is free */
! 		if ((pwptr = getpwnam(utmp.ut_name)) == NULL )
  			continue;	/* can't figure out who's on it */
  		uid = pwptr->pw_uid;
  		if (sel_user && strncmp(utmp.ut_name, sel_user, 8) != 0)

--- 235,243 -----
  		}
  		if (utmp.ut_name[0] == '\0')
  			continue;	/* that tty is free */
! 		strncpy(tmp, utmp.ut_name, 8);
! 		tmp[8] = '\0';		/* make sure it's null-terminated */
! 		if ((pwptr = getpwnam(tmp)) == NULL )
  			continue;	/* can't figure out who's on it */
  		uid = pwptr->pw_uid;
  		if (sel_user && strncmp(utmp.ut_name, sel_user, 8) != 0)



More information about the Comp.bugs.2bsd mailing list