]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - login-utils/last.c
last: do not use non-standard __UT_NAMESIZE
[thirdparty/util-linux.git] / login-utils / last.c
index f2e8f834e84e9a8678f877d81b71ef11a82d9d90..303adeacd8988255ebf1275cf40de0d4bdd8561f 100644 (file)
@@ -349,7 +349,7 @@ static int time_formatter(int fmt, char *dst, size_t dlen, time_t *when)
                ret = rtrim_whitespace((unsigned char *) dst);
                break;
        case LAST_TIMEFTM_ISO8601:
-               ret = strtime_iso(when, ISO_8601_DATE|ISO_8601_TIME|ISO_8601_TIMEZONE, dst, dlen);
+               ret = strtime_iso(when, ISO_TIMESTAMP_T, dst, dlen);
                break;
        default:
                abort();
@@ -395,7 +395,7 @@ static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_t
         *      uucp and ftp have special-type entries
         */
        utline[0] = 0;
-       strncat(utline, p->ut_line, sizeof(p->ut_line));
+       strncat(utline, p->ut_line, sizeof(utline) - 1);
        if (strncmp(utline, "ftp", 3) == 0 && isdigit(utline[3]))
                utline[3] = 0;
        if (strncmp(utline, "uucp", 4) == 0 && isdigit(utline[4]))
@@ -508,15 +508,8 @@ static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_t
        r = -1;
        if (ctl->usedns || ctl->useip)
                r = dns_lookup(domain, sizeof(domain), ctl->useip, (int32_t*)p->ut_addr_v6);
-       if (r < 0) {
-               size_t sz = sizeof(p->ut_host);
-
-               if (sz > sizeof(domain))
-                       sz = sizeof(domain);
-
-               xstrncpy(domain, p->ut_host, sz);
-       }
-
+       if (r < 0)
+               mem2strcpy(domain, p->ut_host, sizeof(p->ut_host), sizeof(domain));
 
        if (ctl->showhost) {
                if (!ctl->altlist) {
@@ -607,6 +600,7 @@ static int is_phantom(const struct last_control *ctl, struct utmpx *ut)
 
        if (ut->ut_tv.tv_sec < ctl->boot_time.tv_sec)
                return 1;
+       ut->ut_user[sizeof(ut->ut_user) - 1] = '\0';
        pw = getpwnam(ut->ut_user);
        if (!pw)
                return 1;