From cced1e49ef25eae20773342a23af1e0d3dd27d30 Mon Sep 17 00:00:00 2001 From: Thorsten Kukuk Date: Tue, 7 Mar 2023 11:42:20 +0100 Subject: [PATCH] w: make sure null terminated ut_* strings are used strncpy does not null terminate a string if it has the maximal length. Use always the null terminated variants for ut_user and ut_line. Signed-off-by: Thorsten Kukuk --- src/w.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/w.c b/src/w.c index 5e878f04..80a867b9 100644 --- a/src/w.c +++ b/src/w.c @@ -32,8 +32,6 @@ #include #include #include -#include -#include #include #include #include @@ -490,9 +488,10 @@ static void showinfo( /* force NUL term for printf */ strncpy(uname, u->ut_user, UT_NAMESIZE); + uname[UT_NAMESIZE] = '\0'; if (formtype) { - printf("%-*.*s%-9.8s", userlen + 1, userlen, uname, u->ut_line); + printf("%-*.*s%-9.8s", userlen + 1, userlen, uname, tty + 5); if (from) print_from(u, ip_addresses, fromlen); #ifdef HAVE_UTMPX_H @@ -514,8 +513,7 @@ static void showinfo( else printf(" ? "); } else { - printf("%-*.*s%-9.8s", userlen + 1, userlen, u->ut_user, - u->ut_line); + printf("%-*.*s%-9.8s", userlen + 1, userlen, uname, tty + 5); if (from) print_from(u, ip_addresses, fromlen); if (*u->ut_line == ':')