+2009-04-22 Nicolas François <nicolas.francois@centraliens.net>
+
+ * libmisc/utmp.c: The name returned by ttyame() needs to be copied
+ locally.
+
2009-04-22 Nicolas François <nicolas.francois@centraliens.net>
* src/login.c: Added assert()s for NULL (or ! NULL) username, and
*/
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;