diff options
author | Alejandro Colomar <alx@kernel.org> | 2024-02-18 18:36:04 +0100 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2024-02-20 22:53:54 +0100 |
commit | 02a9d041a37edba1af1662f5cb4d695ca41d3f1c (patch) | |
tree | 5c56ca6c705f1b78dabc5f1c7db61815fd12d3e6 | |
parent | bec925d29db92f71494df41849b23123bd669a6c (diff) |
lib/utmp.c: Replace UT_LINESIZE by a NITEMS() calculation
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>
Cc: Firas Khalil Khana <firasuke@gmail.com>
Cc: "A. Wilfox" <https://github.com/awilfox>
Cherry-picked-from: 5ff6edf9f29e ("lib/utmp.c: Replace UT_LINESIZE by a NITEMS() calculation")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r-- | lib/utmp.c | 10 | ||||
-rw-r--r-- | src/logoutd.c | 2 |
2 files changed, 8 insertions, 4 deletions
@@ -27,19 +27,23 @@ #ident "$Id$" +#define UTX_LINESIZE NITEMS((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); diff --git a/src/logoutd.c b/src/logoutd.c index 9a5d11e8..3cfecaee 100644 --- a/src/logoutd.c +++ b/src/logoutd.c @@ -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 |