]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/utmp.c: Replace UT_LINESIZE by a NITEMS() calculation
authorAlejandro Colomar <alx@kernel.org>
Sun, 18 Feb 2024 17:36:04 +0000 (18:36 +0100)
committerAlejandro Colomar <alx@kernel.org>
Tue, 20 Feb 2024 17:53:53 +0000 (18:53 +0100)
A difference between 'struct utmp' and 'struct utmpx' is that
the former uses UT_LINESIZE for the size of its array members,
while the latter doesn't have a standard variable to get its
size.  Therefore, we need to get the number of elements in
the array with NITEMS().

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/utmp.c
src/logoutd.c

index 6c8f43ea4accdec3b9d49d491f9beda30da59673..388383e9254479ad07cdf9842d57946ea931d465 100644 (file)
 #ident "$Id$"
 
 
+#define UTX_LINESIZE  NITEMS(memberof(struct utmpx, ut_line))
+
+
 /*
  * is_my_tty -- determine if "tty" is the same TTY stdin is using
  */
-static bool is_my_tty (const char tty[UT_LINESIZE])
+static bool
+is_my_tty(const char tty[UTX_LINESIZE])
 {
-       char         full_tty[STRLEN("/dev/") + UT_LINESIZE + 1];
+       char         full_tty[STRLEN("/dev/") + UTX_LINESIZE + 1];
        /* tmptty shall be bigger than full_tty */
        static char  tmptty[sizeof(full_tty) + 1];
 
        full_tty[0] = '\0';
        if (tty[0] != '/')
                strcpy (full_tty, "/dev/");
-       strncat (full_tty, tty, UT_LINESIZE);
+       strncat(full_tty, tty, UTX_LINESIZE);
 
        if ('\0' == tmptty[0]) {
                const char *tname = ttyname (STDIN_FILENO);
index cc7c2013bb43e23bc2e8c3fec6ca85d574b3cfde..eac118cb735d5270d1d4154c4563d04c4ff42a7d 100644 (file)
@@ -212,7 +212,7 @@ main(int argc, char **argv)
                                tty_name[0] = '\0';
                        }
 
-                       strncat (tty_name, ut->ut_line, UT_LINESIZE);
+                       strncat(tty_name, ut->ut_line, NITEMS(ut->ut_line));
 #ifndef O_NOCTTY
 #define O_NOCTTY 0
 #endif