From bd2aece45eea531c3317e57b1ba06b30c4304554 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 13 Mar 2017 12:55:44 +0100 Subject: [PATCH] last: use domain string more carefully Use xstrcpy() to explicitly terminate the domain string. Reported-by: Tobias Stoeckmann Signed-off-by: Karel Zak --- login-utils/last.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/login-utils/last.c b/login-utils/last.c index 340705757..679ea6c12 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -505,10 +505,12 @@ static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_t if (ctl->usedns || ctl->useip) r = dns_lookup(domain, sizeof(domain), ctl->useip, p->ut_addr_v6); if (r < 0) { - len = sizeof(p->ut_host); - if (len >= (int)sizeof(domain)) len = sizeof(domain) - 1; - domain[0] = 0; - strncat(domain, p->ut_host, len); + size_t sz = sizeof(p->ut_host); + + if (sz > sizeof(domain)) + sz = sizeof(domain); + + xstrncpy(domain, p->ut_host, sz); }