]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
last: fix use of non-terminated utmp->ut_line
authorKarel Zak <kzak@redhat.com>
Thu, 9 Jul 2020 08:10:58 +0000 (10:10 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 9 Jul 2020 08:10:58 +0000 (10:10 +0200)
Addresses: https://github.com/karelzak/util-linux/pull/1097
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/last.c

index 77c5e1b47f0d7cffb2f047345a908f1ab6e988a6..9d71ba4435d93fdba6d013a12df269349e581dda 100644 (file)
@@ -612,7 +612,7 @@ static int is_phantom(const struct last_control *ctl, struct utmpx *ut)
        pw = getpwnam(ut->ut_user);
        if (!pw)
                return 1;
-       sprintf(path, "/proc/%u/loginuid", ut->ut_pid);
+       snprintf(path, sizeof(path), "/proc/%u/loginuid", ut->ut_pid);
        if (access(path, R_OK) == 0) {
                unsigned int loginuid;
                FILE *f = NULL;
@@ -626,8 +626,11 @@ static int is_phantom(const struct last_control *ctl, struct utmpx *ut)
                        return 1;
        } else {
                struct stat st;
+               char utline[sizeof(ut->ut_line) + 1];
 
-               sprintf(path, "/dev/%s", ut->ut_line);
+               mem2strcpy(utline, ut->ut_line, sizeof(ut->ut_line), sizeof(utline));
+
+               snprintf(path, sizeof(path), "/dev/%s", utline);
                if (stat(path, &st))
                        return 1;
                if (pw->pw_uid != st.st_uid)