last: use domain string more carefully

Use xstrcpy() to explicitly terminate the domain string.

Reported-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2017-03-13 12:55:44 +01:00
parent b0f97de5a4
commit bd2aece45e
1 changed files with 6 additions and 4 deletions

View File

@ -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);
}