Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37559142
en ru br
ALT Linux repos
S:2.5.0-alt1
5.0: 2.4.4-alt11
4.1: 2.4.4-alt10.M41.1
4.0: 2.4.4-alt10
+updates:2.4.4-alt10
3.0: 2.4.2-alt6
+updates:2.4.2-alt6.M30.1

Group :: Networking/Other
RPM: ppp

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

Patch: ppp-2.4.3-fork-fix.diff
Download


diff -ur ppp-2.4.3.old/pppd/main.c ppp-2.4.3/pppd/main.c
--- ppp-2.4.3.old/pppd/main.c	2005-06-18 17:48:50.000000000 +0200
+++ ppp-2.4.3/pppd/main.c	2005-06-20 11:03:43.000000000 +0200
@@ -1457,14 +1457,6 @@
 	int fd, pipefd[2];
 	char buf[1];
 
-	/* make sure fds 0, 1, 2 are occupied (probably not necessary) */
-	while ((fd = dup(fd_devnull)) >= 0) {
-		if (fd > 2) {
-			close(fd);
-			break;
-		}
-	}
-
 	if (pipe(pipefd) == -1)
 		pipefd[0] = pipefd[1] = -1;
 	pid = fork();
@@ -1487,24 +1479,30 @@
 	tdb_close(pppdb);
 #endif
 
-	/* make sure infd, outfd and errfd won't get tromped on below */
-	if (infd == 1 || infd == 2)
-		infd = dup(infd);
-	if (outfd == 0 || outfd == 2)
-		outfd = dup(outfd);
-	if (errfd == 0 || errfd == 1)
-		errfd = dup(errfd);
+	/* make sure fds 0, 1, 2 are occupied, so the duplicated  fds always > 2 */
+	while ((fd = dup(fd_devnull)) >= 0) {
+		if (fd > 2) {
+			close(fd);
+			break;
+		}
+	}
 
-	/* dup the in, out, err fds to 0, 1, 2 */
-	if (infd != 0)
-		dup2(infd, 0);
-	if (outfd != 1)
-		dup2(outfd, 1);
-	if (errfd != 2)
-		dup2(errfd, 2);
+	/* always copy fd's to avoid to use a already closed fd later */
+	{
+		int	fdi = infd, fdo = outfd;
 
+		infd = dup(infd);
+		outfd = dup(outfd);
+		if (errfd >= 0) {
+			fd = errfd;
+			errfd = dup(errfd);
+			close(fd);
+		}
+		close(fdi);
+		close(fdo);
+	}
 	closelog();
-	if (log_to_fd > 2)
+	if (log_to_fd >= 0)
 		close(log_to_fd);
 	if (the_channel->close)
 		(*the_channel->close)();
@@ -1512,12 +1510,18 @@
 		close(devfd);	/* some plugins don't have a close function */
 	close(fd_ppp);
 	close(fd_devnull);
-	if (infd != 0)
-		close(infd);
-	if (outfd != 1)
-		close(outfd);
-	if (errfd != 2)
+
+	close(0);
+	dup2(infd, 0);
+	close(infd);
+	close(1);
+	dup2(outfd, 1);
+	close(outfd);
+	if (errfd >= 0) {
+		close(2);
+		dup2(errfd, 2);
 		close(errfd);
+	}
 
 	notify(fork_notifier, 0);
 	close(pipefd[0]);
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin