]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
last: use full size of the username
authorKarel Zak <kzak@redhat.com>
Mon, 13 Feb 2023 15:22:23 +0000 (16:22 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 13 Feb 2023 15:22:23 +0000 (16:22 +0100)
utmp uses 32 bytes for username, last(1) truncates it to 31 when calls getpwnam().

Reported-by: Radka Skvarilova <rskvaril@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/last.1.adoc
login-utils/last.c

index 1157ae957168da8df7a800d01c3d874527a4a546..04d407387f21273472567c8f046a129d442754ab 100644 (file)
@@ -117,6 +117,8 @@ The files _wtmp_ and _btmp_ might not be found. The system only logs information
 
 An empty entry is a valid type of wtmp entry. It means that an empty file or file with zeros is not interpreted as an error.
 
+The utmp file format uses fixed sizes of strings, which means that very long strings are impossible to store in the file and impossible to display by last. The usual limits are 32 bytes for a user and line name and 256 bytes for a hostname.
+
 == AUTHORS
 
 mailto:miquels@cistron.nl[Miquel van Smoorenburg]
index 260a9f35e80470af975b21c5b085c31d4fd9157e..d3eeed4b6e5489956b0037e53e4912d93573053e 100644 (file)
@@ -602,12 +602,14 @@ static int is_phantom(const struct last_control *ctl, struct utmpx *ut)
 {
        struct passwd *pw;
        char path[sizeof(ut->ut_line) + 16];
+       char user[sizeof(ut->ut_user) + 1];
        int ret = 0;
 
        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);
+
+       mem2strcpy(user, ut->ut_user, sizeof(ut->ut_user), sizeof(user));
+       pw = getpwnam(user);
        if (!pw)
                return 1;
        snprintf(path, sizeof(path), "/proc/%u/loginuid", ut->ut_pid);