summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Kukuk <kukuk@suse.com>2023-03-07 11:42:20 +0100
committerCraig Small <csmall@dropbear.xyz>2023-03-08 07:30:56 +1100
commitcced1e49ef25eae20773342a23af1e0d3dd27d30 (patch)
treeb5a3f5c962a44f09de53a73e8a1c51fe4f95202e
parent133a833942224a9ae4cd049d62a3fa54e95c5a2a (diff)
downloadprocps-ng-cced1e49ef25eae20773342a23af1e0d3dd27d30.tar.gz
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 <kukuk@suse.com>
-rw-r--r--src/w.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/w.c b/src/w.c
index 5e878f0..80a867b 100644
--- a/src/w.c
+++ b/src/w.c
@@ -32,8 +32,6 @@
#include <getopt.h>
#include <limits.h>
#include <locale.h>
-#include <locale.h>
-#include <pwd.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
@@ -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 == ':')