vte r2363 - in trunk: . gnome-pty-helper



Author: chpe
Date: Tue Jan 20 18:44:30 2009
New Revision: 2363
URL: http://svn.gnome.org/viewvc/vte?rev=2363&view=rev

Log:
	* gnome-pty-helper/gnome-pty-helper.c: (init_term_with_defaults),
	(open_ptys), (close_pty_pair): Use ttyname() as recommended in the
	glibc manual. Bug #565688.

Modified:
   trunk/ChangeLog
   trunk/gnome-pty-helper/gnome-pty-helper.c

Modified: trunk/gnome-pty-helper/gnome-pty-helper.c
==============================================================================
--- trunk/gnome-pty-helper/gnome-pty-helper.c	(original)
+++ trunk/gnome-pty-helper/gnome-pty-helper.c	Tue Jan 20 18:44:30 2009
@@ -270,20 +270,6 @@
 	return pi;
 }
 
-static int
-path_max (void)
-{
-#ifdef _PC_PATH_MAX
-	return pathconf ("/", _PC_PATH_MAX);
-#else
-#  ifdef PATH_MAX
-	return PATH_MAX;
-#  else
-	return 1024;
-#  endif
-#endif
-}
-
 static struct termios*
 init_term_with_defaults(struct termios* term)
 {
@@ -453,7 +439,7 @@
 static int
 open_ptys (int utmp, int wtmp, int lastlog)
 {
-	char *term_name;
+	const char *term_name;
 	int status, master_pty, slave_pty;
 	pty_info *p;
 	int result;
@@ -462,11 +448,6 @@
 	struct group *group_info;
 	struct termios term;
 
-	term_name = (char *) malloc (path_max () + 1);
-
-	if (term_name == NULL) {
-		exit (1);
-	}
 	/* Initialize term */
 	init_term_with_defaults(&term);
 
@@ -485,7 +466,7 @@
 #error "No means to drop privileges! Huge security risk! Won't compile."
 #endif
 	/* Open pty with privileges of the user */
-	status = openpty (&master_pty, &slave_pty, term_name, &term, NULL);
+	status = openpty (&master_pty, &slave_pty, NULL, &term, NULL);
 
 	/* Restore saved privileges to root */
 #ifdef HAVE_SETEUID
@@ -498,10 +479,9 @@
 #error "No means to raise privileges! Huge security risk! Won't compile."
 #endif
 	/* openpty() failed, reject request */
-	if (status == -1) {
+	if (status == -1 || (term_name = ttyname(slave_pty)) == NULL) {
 		result = 0;
 		n_write (STDIN_FILENO, &result, sizeof (result));
-		free (term_name);
 		return 0;
 	}
 
@@ -521,7 +501,6 @@
 	    n_write (STDIN_FILENO, &p, sizeof (p)) != sizeof (p) ||
 	    pass_fd (STDOUT_FILENO, master_pty)  == -1 ||
 	    pass_fd (STDOUT_FILENO, slave_pty)   == -1) {
-		free (term_name);
 		exit (0);
 	}
 
@@ -532,7 +511,6 @@
 
 	close (master_pty);
 	close (slave_pty);
-	free (term_name);
 
 	return 1;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]