From: Alejandro Colomar Date: Fri, 24 Oct 2025 09:55:06 +0000 (+0200) Subject: lib/utmp.c: is_my_tty(): Use ttyname_r(3) to make it re-entrant X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5686ab8744563489256c86c3b47df75ed8dee68d;p=thirdparty%2Fshadow.git lib/utmp.c: is_my_tty(): Use ttyname_r(3) to make it re-entrant Reviewed-by: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/utmp.c b/lib/utmp.c index 2c98293f8..98348583e 100644 --- a/lib/utmp.c +++ b/lib/utmp.c @@ -25,6 +25,7 @@ #include #include #include +#include #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" @@ -51,16 +51,15 @@ 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); }