]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login-utils: avoid using the defined utmp sizes.
authorRuediger Meier <ruediger.meier@ga-group.nl>
Thu, 1 Dec 2016 08:52:08 +0000 (09:52 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 7 Dec 2016 11:35:24 +0000 (12:35 +0100)
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
login-utils/last.c
term-utils/write.c

index 42fb914d8fc85e0461dd6e371305d9a3a0634c7b..da7ed36c8e78f59fe44007e26c68aed14c0a677e 100644 (file)
@@ -383,7 +383,7 @@ static int list(const struct last_control *ctl, struct utmp *p, time_t logout_ti
        char            logouttime[LAST_TIMESTAMP_LEN];
        char            length[LAST_TIMESTAMP_LEN];
        char            final[512];
-       char            utline[UT_LINESIZE+1];
+       char            utline[sizeof(p->ut_line) + 1];
        char            domain[256];
        char            *s;
        int             mins, hours, days;
@@ -394,7 +394,7 @@ static int list(const struct last_control *ctl, struct utmp *p, time_t logout_ti
         *      uucp and ftp have special-type entries
         */
        utline[0] = 0;
-       strncat(utline, p->ut_line, UT_LINESIZE);
+       strncat(utline, p->ut_line, sizeof(p->ut_line));
        if (strncmp(utline, "ftp", 3) == 0 && isdigit(utline[3]))
                utline[3] = 0;
        if (strncmp(utline, "uucp", 4) == 0 && isdigit(utline[4]))
@@ -406,7 +406,7 @@ static int list(const struct last_control *ctl, struct utmp *p, time_t logout_ti
        if (ctl->show) {
                char **walk;
                for (walk = ctl->show; *walk; walk++) {
-                       if (strncmp(p->ut_user, *walk, UT_NAMESIZE) == 0 ||
+                       if (strncmp(p->ut_user, *walk, sizeof(p->ut_user)) == 0 ||
                            strcmp(utline, *walk) == 0 ||
                            (strncmp(utline, "tty", 3) == 0 &&
                             strcmp(utline + 3, *walk) == 0)) break;
@@ -504,7 +504,7 @@ static int list(const struct last_control *ctl, struct utmp *p, time_t logout_ti
        if (ctl->usedns || ctl->useip)
                r = dns_lookup(domain, sizeof(domain), ctl->useip, p->ut_addr_v6);
        if (r < 0) {
-               len = UT_HOSTSIZE;
+               len = sizeof(p->ut_host);
                if (len >= (int)sizeof(domain)) len = sizeof(domain) - 1;
                domain[0] = 0;
                strncat(domain, p->ut_host, len);
@@ -798,7 +798,7 @@ static void process_wtmp_file(const struct last_control *ctl,
                        for (p = ulist; p; p = next) {
                                next = p->next;
                                if (strncmp(p->ut.ut_line, ut.ut_line,
-                                   UT_LINESIZE) == 0) {
+                                   sizeof(ut.ut_line)) == 0) {
                                        /* Show it */
                                        if (c == 0) {
                                                quit = list(ctl, &ut, p->ut.ut_tv.tv_sec, R_NORMAL);
@@ -987,10 +987,10 @@ int main(int argc, char **argv)
                        ctl.until = (time_t) (p / 1000000);
                        break;
                case 'w':
-                       if (ctl.name_len < UT_NAMESIZE)
-                               ctl.name_len = UT_NAMESIZE;
-                       if (ctl.domain_len < UT_HOSTSIZE)
-                               ctl.domain_len = UT_HOSTSIZE;
+                       if (ctl.name_len < sizeof(((struct utmp *) 0)->ut_user))
+                               ctl.name_len = sizeof(((struct utmp *) 0)->ut_user);
+                       if (ctl.domain_len < sizeof(((struct utmp *) 0)->ut_host))
+                               ctl.domain_len = sizeof(((struct utmp *) 0)->ut_host);
                        break;
                case '0': case '1': case '2': case '3': case '4':
                case '5': case '6': case '7': case '8': case '9':
index e39b848eaef699e1c5ed3afb1c82b24d877b73ac..4f8f21eb575c8a6f088f9412b7d336f57acc8821 100644 (file)
@@ -164,7 +164,7 @@ static void search_utmp(struct write_control *ctl)
        struct utmp *u;
        time_t best_atime = 0, tty_atime;
        int num_ttys = 0, valid_ttys = 0, tty_writeable = 0, user_is_me = 0;
-       char path[UT_LINESIZE + 6];
+       char path[sizeof(u->ut_line) + 6];
 
        utmpname(_PATH_UTMP);
        setutent();