]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
last: use domain string more carefully
authorKarel Zak <kzak@redhat.com>
Mon, 13 Mar 2017 11:55:44 +0000 (12:55 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 13 Mar 2017 11:55:44 +0000 (12:55 +0100)
Use xstrcpy() to explicitly terminate the domain string.

Reported-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/last.c

index 340705757849be3ee39a786f399ca495d9267e87..679ea6c123325ab0c0b63a3f69b36d4f36553f07 100644 (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);
        }