This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
FreeBSD port (16): tst-utmp makes invalid assumptions
- From: Bruno Haible <bruno at clisp dot org>
- To: libc-alpha at sources dot redhat dot com
- Date: Wed, 10 Jul 2002 20:06:38 +0200 (CEST)
- Subject: FreeBSD port (16): tst-utmp makes invalid assumptions
Hi,
tst-utmp makes the assumption that writing a record for ut_user = "\0lbert\0"
and then fetching the record back from the file will return the same ut_user,
including all bytes after the first NUL byte.
But the glibc/FreeBSD implementation of the utmpx functions maps the utmpx
records to smaller utmp records, and in doing that it drops everything after
the first NUL byte of every field of 'struct utmpx' that is of type char[].
Moreover tst-utmp makes the assumption that such an ut_user is read and
written when ut_type == DEAD_PROCESS. But SUSV3 functions/getutxent.html has
a table showing that ut_user is irrelevant in this case.
I think the tst-utmp assumptions are unreasonable. It can be fixed either
by changing the test to always zero-fill the ut_user entry. Or by changing
the memcmp comparisons to some more elaborate comparison function. Here is
a patch implementing the first fix.
2002-07-06 Bruno Haible <bruno@clisp.org>
* login/tst-utmp.c (simulate_login): Don't leave garbage after the
nul byte in entry[n].ut_user.
(simulate_logout): Likewise.
diff -r -c3 glibc-20020627.bak/login/tst-utmp.c glibc-20020627/login/tst-utmp.c
--- glibc-20020627.bak/login/tst-utmp.c Tue Jul 10 22:59:11 2001
+++ glibc-20020627/login/tst-utmp.c Fri Jul 5 01:17:06 2002
@@ -165,7 +167,7 @@
if (entry[n].ut_pid == DEAD_PROCESS)
entry[n].ut_pid = (entry_pid += 27);
entry[n].ut_type = USER_PROCESS;
- strcpy (entry[n].ut_user, user);
+ strncpy (entry[n].ut_user, user, sizeof (entry[n].ut_user));
#if _HAVE_UT_TV - 0 || defined UTMPX
entry[n].ut_tv.tv_sec = (entry_time += 1000);
#else
@@ -199,7 +201,7 @@
if (strcmp (line, entry[n].ut_line) == 0)
{
entry[n].ut_type = DEAD_PROCESS;
- entry[n].ut_user[0] = '\0';
+ strncpy (entry[n].ut_user, "", sizeof (entry[n].ut_user));
#if _HAVE_UT_TV - 0 || defined UTMPX
entry[n].ut_tv.tv_sec = (entry_time += 1000);
#else