diff --git a/lib/utmp.c b/lib/utmp.c index be8efa34..f202abe3 100644 --- a/lib/utmp.c +++ b/lib/utmp.c @@ -24,6 +24,7 @@ #include "alloc.h" #include "sizeof.h" +#include "zustr2stp.h" #ident "$Id$" @@ -244,9 +245,8 @@ static #ifdef HAVE_STRUCT_UTMP_UT_HOST } else if ( (NULL != ut) && ('\0' != ut->ut_host[0])) { - hostname = XMALLOC(sizeof(ut->ut_host) + 1, char); - strncpy (hostname, ut->ut_host, sizeof (ut->ut_host)); - hostname[sizeof (ut->ut_host)] = '\0'; + hostname = XMALLOC(SIZEOF_ARRAY(ut->ut_host) + 1, char); + zustr2stp(hostname, ut->ut_host, SIZEOF_ARRAY(ut->ut_host)); #endif /* HAVE_STRUCT_UTMP_UT_HOST */ } diff --git a/src/logoutd.c b/src/logoutd.c index 3a833d88..2612a178 100644 --- a/src/logoutd.c +++ b/src/logoutd.c @@ -19,6 +19,8 @@ #include "defines.h" #include "prototypes.h" #include "shadowlog.h" +#include "sizeof.h" +#include "zustr2stp.h" /* * Global variables */ @@ -44,11 +46,7 @@ static int check_login (const struct utmp *ut) char user[sizeof (ut->ut_user) + 1]; time_t now; - /* - * ut_user may not have the terminating NUL. - */ - strncpy (user, ut->ut_user, sizeof (ut->ut_user)); - user[sizeof (ut->ut_user)] = '\0'; + zustr2stp(user, ut->ut_user, SIZEOF_ARRAY(ut->ut_user)); (void) time (&now); @@ -226,8 +224,7 @@ int main (int argc, char **argv) kill (-ut->ut_pid, SIGKILL); } - strncpy (user, ut->ut_user, sizeof (user) - 1); - user[sizeof (user) - 1] = '\0'; + zustr2stp(user, ut->ut_user, SIZEOF_ARRAY(ut->ut_user)); SYSLOG ((LOG_NOTICE, "logged off user '%s' on '%s'", user,