]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
last: do not use non-standard __UT_NAMESIZE
authorPatrick Steinhardt <ps@pks.im>
Fri, 1 Mar 2019 17:35:49 +0000 (18:35 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 2 Apr 2019 10:57:52 +0000 (12:57 +0200)
In commit b22332dd4 (last: fix wtmp user name buffer overflow
[asan], 2019-01-13), we started to make sure that the `ut_user`
field of the `utmpx` struct is always NUL-terminated. The
implementation makes use of the `__UT_NAMESIZE` define to
determine the position of the last character in that array. The
problem is that this is a non-standard define that is not
necessarily available on non-glibc platforms.

As there is no standardized define, we should just use `sizeof`.
This fixes compilation on musl libc based systems.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
login-utils/last.c

index be744b079198ecf11ba05eed990c5f942bca18c0..303adeacd8988255ebf1275cf40de0d4bdd8561f 100644 (file)
@@ -600,7 +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[__UT_NAMESIZE - 1] = '\0';
+       ut->ut_user[sizeof(ut->ut_user) - 1] = '\0';
        pw = getpwnam(ut->ut_user);
        if (!pw)
                return 1;