]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/utmp.c: Fixed generated strings for "ut_id"
authorEvgeny Grin (Karlson2k) <k2k@drgrin.dev>
Mon, 14 Jul 2025 20:05:21 +0000 (22:05 +0200)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Thu, 17 Jul 2025 10:55:02 +0000 (12:55 +0200)
When no "ut_id" is provided by previous utmp file entry, "login" must
generate its own "ut_id". Historically tty number  was used for it.
However, if current device name is three characters or shorter, then
empty "ut_id" is produced or even garbage is copied from uninitialised
part of the "line".
This commit fixes it.
This patch uses unportable C extension Elvis operator as it is already
used everywhere in the code.

Signed-off-by: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
lib/utmp.c

index c8a287c38d960d30836a809e7923069ccfee40fe..11e6b190d11cd535132e5ee5318aeae4e5cd1fc4 100644 (file)
@@ -274,8 +274,7 @@ prepare_utmp(const char *name, const char *line, const char *host,
        if (NULL != ut) {
                STRNCPY(utent->ut_id, ut->ut_id);
        } else {
-               /* XXX - assumes /dev/tty?? */
-               STRNCPY(utent->ut_id, line + 3);
+               STRNCPY(utent->ut_id, strprefix(line, "tty") ?: line);
        }
 #if defined(HAVE_STRUCT_UTMPX_UT_NAME)
        STRNCPY(utent->ut_name, name);