Apur-phy.260
net.bugs.2bsd
utcsrgv!utzoo!decvax!pur-ee!purdue!pur-phy!crl
Mon Mar 29 13:27:45 1982
A fix to the w.c bug fix (sigh)
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)

-----------------------------------------------------------------
gopher://quux.org/ conversion by John Goerzen <[email protected]>
of http://communication.ucsd.edu/A-News/


This Usenet Oldnews Archive
article may be copied and distributed freely, provided:

1. There is no money collected for the text(s) of the articles.

2. The following notice remains appended to each copy:

The Usenet Oldnews Archive: Compilation Copyright (C) 1981, 1996
Bruce Jones, Henry Spencer, David Wiseman.