[Pkg-shadow-commits] r2753 - in upstream/trunk: . libmisc

Nicolas FRANÇOIS nekral-guest at alioth.debian.org
Wed Apr 22 20:57:29 UTC 2009


Author: nekral-guest
Date: 2009-04-22 20:57:29 +0000 (Wed, 22 Apr 2009)
New Revision: 2753

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/libmisc/utmp.c
Log:
	* libmisc/utmp.c: The name returned by ttyame() needs to be copied
	locally.


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2009-04-22 20:53:15 UTC (rev 2752)
+++ upstream/trunk/ChangeLog	2009-04-22 20:57:29 UTC (rev 2753)
@@ -1,5 +1,10 @@
 2009-04-22  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* libmisc/utmp.c: The name returned by ttyame() needs to be copied
+	locally.
+
+2009-04-22  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* src/login.c: Added assert()s for NULL (or ! NULL) username, and
 	pwd. This helps splint.
 	* src/login.c: Added splint annotations.

Modified: upstream/trunk/libmisc/utmp.c
===================================================================
--- upstream/trunk/libmisc/utmp.c	2009-04-22 20:53:15 UTC (rev 2752)
+++ upstream/trunk/libmisc/utmp.c	2009-04-22 20:57:29 UTC (rev 2753)
@@ -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;




More information about the Pkg-shadow-commits mailing list