]> granicus.if.org Git - shadow/commitdiff
* libmisc/utmp.c: The name returned by ttyame() needs to be copied
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Wed, 22 Apr 2009 20:57:29 +0000 (20:57 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Wed, 22 Apr 2009 20:57:29 +0000 (20:57 +0000)
locally.

ChangeLog
libmisc/utmp.c

index 9cde1a664983e5ac82140b41ee32ea6639e798fe..0a6d4f1e8e03a999c26978331c532b8c2e5474a2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+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
index 32843a1cb82abb8960c4f213d2bbbf9584d6168f..edd381c2c8c007ef19906646df4f2e6329a05bac 100644 (file)
  */
 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;