From: steve@Nyongwa.CAM.ORG (Steve M. Robbins) Subject: Re: Fix for getty/uugetty under pl5 Date: Thu, 19 Nov 1992 04:19:53 GMT
In article <1992Nov18.011322.9917@galileo.cc.rochester.edu> ctne_ltd@uhura.cc.rochester.edu (Chris Newbold) writes:
>I've found the problem with the getty/uugetty from getty_ps203.
>
>The culprit is the code which attempts to add an entry into utmp
>for uugetty. Notice that the ifdef explicitly excludes the code
>which initializes utmp; the subsequent strncopys try to copy
>stuff to a NULL structure:
>
>From main.c:585:
>
>#ifndef linux
> while ((utmp = getutent()) != (struct utmp *) NULL)
> if (utmp->ut_type == INIT_PROCESS && utmp->ut_pid == pid)
>#endif
> {
> debug2(D_UTMP, "logutmp entry made\n");
> /* show login process in utmp
> */
> strncopy(utmp->ut_line, Device);
> strncopy(utmp->ut_id, Device+3);
Ooops. That was stupid, wasn't it?
>I don't know enough about this to say what the real fix is (maybe
>it should be "#ifdef", I dunno. Perhaps the person who did the
>original port can comment.
Okay, the reason I #ifdef'd out the loop to search through utmp was that
the init (simpleinit from poe) that I have does not create INIT_PROCESS
entries. The result is that the loop here never finds an entry, and doesn't
overwrite it. So the last person to use the line will *always* show up in
'who' until someone else logs in, because 'login' doesn't bother checking --
it ALWAYS writes a utmp entry.
Poe's getty did no utmp checking, so I copied him. And I goofed.
The fix is then to malloc the memory for utmp before trying to use it.
(Is the real fix to have init write INIT_PROCESS entries?)
Now: can someone explain why it took until pl5 for this to show up? Since the
pointer utmp is a local variable to function main(), doesn't it have the
value 0? If it does, how come writing all this junk to location zero doesn't
overwrite other valuable things and just crash royally?
Here's my aforementioned patch:
===========================================================================
*** main.old Wed Nov 18 22:50:05 1992
--- main.c Wed Nov 18 23:02:55 1992
***************
*** 579,585 ****
debug2(D_RUN, "update utmp/wtmp files\n");
pid = getpid();
! #ifndef linux
while ((utmp = getutent()) != (struct utmp *) NULL)
if (utmp->ut_type == INIT_PROCESS && utmp->ut_pid == pid)
#endif
--- 579,587 ----
debug2(D_RUN, "update utmp/wtmp files\n");
pid = getpid();
! #ifdef linux
! if ((utmp = malloc(sizeof(struct utmp))) != NULL)
! #else
while ((utmp = getutent()) != (struct utmp *) NULL)
if (utmp->ut_type == INIT_PROCESS && utmp->ut_pid == pid)
#endif
===========================================================================
-- Steve Robbins -- steve@nyongwa.cam.org %SYSTEM-F-ANARCHISM, the operating system has been overthrown