From: nekral-guest Date: Wed, 22 Apr 2009 20:57:29 +0000 (+0000) Subject: * libmisc/utmp.c: The name returned by ttyame() needs to be copied X-Git-Tag: 4.1.4~129 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b05783da32444b5d761a8708ac28ed54370702af;p=shadow * libmisc/utmp.c: The name returned by ttyame() needs to be copied locally. --- diff --git a/ChangeLog b/ChangeLog index 9cde1a66..0a6d4f1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-04-22 Nicolas François + + * libmisc/utmp.c: The name returned by ttyame() needs to be copied + locally. + 2009-04-22 Nicolas François * src/login.c: Added assert()s for NULL (or ! NULL) username, and diff --git a/libmisc/utmp.c b/libmisc/utmp.c index 32843a1c..edd381c2 100644 --- a/libmisc/utmp.c +++ b/libmisc/utmp.c @@ -56,22 +56,28 @@ */ static bool is_my_tty (const char *tty) { + /* full_tty shall be at least sizeof utmp.ut_line + 5 */ char full_tty[200]; - static const char *tmptty = NULL; + /* tmptty shall be bigger than full_tty */ + static char tmptty[sizeof (full_tty)+1]; if ('/' != *tty) { - snprintf (full_tty, sizeof full_tty, "/dev/%s", tty); - tty = full_tty; + (void) snprintf (full_tty, sizeof full_tty, "/dev/%s", tty); + tty = &full_tty[0]; } - if (NULL == tmptty) { - tmptty = ttyname (STDIN_FILENO); + if ('\0' == tmptty[0]) { + const char *tname = ttyname (STDIN_FILENO); + if (NULL != tname) { + (void) strncpy (tmptty, tname, sizeof tmptty); + tmptty[sizeof (tmptty) - 1] = '\0'; + } } if (NULL == tmptty) { (void) puts (_("Unable to determine your tty name.")); exit (EXIT_FAILURE); - } else if (strcmp (tty, tmptty) != 0) { + } else if (strncmp (tty, tmptty, sizeof (tmptty)) != 0) { return false; } else { return true;