summaryrefslogtreecommitdiffstats
path: root/login-utils/login.c
diff options
context:
space:
mode:
authorKarel Zak2007-03-08 23:22:06 +0100
committerKarel Zak2007-03-08 23:22:06 +0100
commit75d4dbb0d7d7937f0f5f464c3bd803d4191a6c0e (patch)
tree3f21ab6cdde2f96990ae71100f56ac684bbff27e /login-utils/login.c
parentlogin: omits PAM account validation when auth is skipped (CVE-2006-7108) (diff)
downloadkernel-qcow2-util-linux-75d4dbb0d7d7937f0f5f464c3bd803d4191a6c0e.tar.gz
kernel-qcow2-util-linux-75d4dbb0d7d7937f0f5f464c3bd803d4191a6c0e.tar.xz
kernel-qcow2-util-linux-75d4dbb0d7d7937f0f5f464c3bd803d4191a6c0e.zip
login: update 32bit utmp correctly on 64bit system
On 64-bit platforms such as x86_64, glibc is usually built with 32-bit compatibility for various structures. One of them is utmp. What this means is that gettimeofday(&ut.ut_tv, NULL) on x86_64 will end up overwriting the first parts of ut_addr_v6, leading to garbage in the utmp file. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils/login.c')
-rw-r--r--login-utils/login.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/login-utils/login.c b/login-utils/login.c
index 1715015d5..d5ec1fc09 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -256,6 +256,7 @@ consoletty(int fd) {
static void
logbtmp(const char *line, const char *username, const char *hostname) {
struct utmp ut;
+ struct timeval tv;
memset(&ut, 0, sizeof(ut));
@@ -266,7 +267,9 @@ logbtmp(const char *line, const char *username, const char *hostname) {
xstrncpy(ut.ut_line, line, sizeof(ut.ut_line));
#if defined(_HAVE_UT_TV) /* in <utmpbits.h> included by <utmp.h> */
- gettimeofday(&ut.ut_tv, NULL);
+ gettimeofday(&tv, NULL);
+ ut.ut_tv.tv_sec = tv.tv_sec;
+ ut.ut_tv.tv_usec = tv.tv_usec;
#else
{
time_t t;
@@ -833,6 +836,7 @@ main(int argc, char **argv)
{
struct utmp ut;
struct utmp *utp;
+ struct timeval tv;
utmpname(_PATH_UTMP);
setutent();
@@ -872,7 +876,9 @@ Michael Riepe <michael@stud.uni-hannover.de>
strncpy(ut.ut_user, username, sizeof(ut.ut_user));
xstrncpy(ut.ut_line, tty_name, sizeof(ut.ut_line));
#ifdef _HAVE_UT_TV /* in <utmpbits.h> included by <utmp.h> */
- gettimeofday(&ut.ut_tv, NULL);
+ gettimeofday(&tv, NULL);
+ ut.ut_tv.tv_sec = tv.tv_sec;
+ ut.ut_tv.tv_usec = tv.tv_usec;
#else
{
time_t t;