]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/utmp.c: is_my_tty(): Use ttyname_r(3) to make it re-entrant
authorAlejandro Colomar <alx@kernel.org>
Fri, 24 Oct 2025 09:55:06 +0000 (11:55 +0200)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Tue, 4 Nov 2025 01:56:30 +0000 (02:56 +0100)
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/utmp.c

index 2c98293f887eb535a2780dcf7f68ed2b8e382a36..98348583e028e843b4c48c391dfca877b0ef9be2 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
+#include <unistd.h>
 
 #include "alloc/calloc.h"
 #include "alloc/malloc.h"
@@ -35,7 +36,6 @@
 #include "string/strcmp/strneq.h"
 #include "string/strcmp/strprefix.h"
 #include "string/strcpy/strncpy.h"
-#include "string/strcpy/strtcpy.h"
 #include "string/strdup/strdup.h"
 #include "string/strdup/strndup.h"
 
 static bool
 is_my_tty(const char tty[UTX_LINESIZE])
 {
-       char         full_tty[STRLEN("/dev/") + UTX_LINESIZE + 1];
-       const char   *my_tty;
+       char  full_tty[STRLEN("/dev/") + UTX_LINESIZE + 1];
+       char  my_tty[countof(full_tty)];
 
        stpcpy(full_tty, "");
        if (tty[0] != '/')
                strcpy (full_tty, "/dev/");
        strncat(full_tty, tty, UTX_LINESIZE);
 
-       my_tty = ttyname(STDIN_FILENO);
-       if (NULL != my_tty)
+       if (ttyname_r(STDIN_FILENO, my_tty, countof(my_tty)) != 0) {
                (void) puts (_("Unable to determine your tty name."));
                exit (EXIT_FAILURE);
        }