Blame SOURCES/sendmail-8.14.3-milterfdleaks.patch

f67e08
Patches by Paul Howarth
f67e08
https://bugzilla.redhat.com/show_bug.cgi?id=485426
f67e08
f67e08
--- sendmail-8.14.3/sendmail/milter.c	2008-09-19 15:51:03.000000000 +0100
f67e08
+++ sendmail-8.14.3/sendmail/milter.c	2008-09-19 16:37:57.000000000 +0100
f67e08
@@ -30,6 +30,9 @@
f67e08
 
f67e08
 # include <sm/fdset.h>
f67e08
 
f67e08
+# include <unistd.h>
f67e08
+# include <fcntl.h>
f67e08
+
f67e08
 static void	milter_connect_timeout __P((int));
f67e08
 static void	milter_error __P((struct milter *, ENVELOPE *));
f67e08
 static int	milter_open __P((struct milter *, bool, ENVELOPE *));
f67e08
@@ -650,6 +653,7 @@
f67e08
 	SOCKADDR_LEN_T addrlen = 0;
f67e08
 	int addrno = 0;
f67e08
 	int save_errno;
f67e08
+	int fdflags;
f67e08
 	char *p;
f67e08
 	char *colon;
f67e08
 	char *at;
f67e08
@@ -1186,6 +1190,21 @@
f67e08
 			   (char *)&nodelay, sizeof(nodelay));
f67e08
 	}
f67e08
 # endif /* MILTER_NO_NAGLE && !defined(TCP_CORK) */
f67e08
+
f67e08
+	/*
f67e08
+	** Need to set close-on-exec for sock to prevent it
f67e08
+	** leaking to the local delivery process
f67e08
+	*/
f67e08
+	if ((fdflags = fcntl(sock, F_GETFD, 0)) == -1 ||
f67e08
+	    fcntl(sock, F_SETFD, fdflags | FD_CLOEXEC) == -1)
f67e08
+	{
f67e08
+		save_errno = errno;
f67e08
+		if (MilterLogLevel > 0)
f67e08
+			sm_syslog(LOG_WARNING, e->e_id,
f67e08
+				"Milter (%s): Unable to set close-on-exec on sock (%s)",
f67e08
+					m->mf_name, sm_errstring(save_errno = errno));
f67e08
+	}
f67e08
+
f67e08
 	return sock;
f67e08
 }
f67e08
 
f67e08
--- sendmail-8.14.3/libmilter/listener.c	2007-04-23 23:22:50.000000000 +0100
f67e08
+++ sendmail-8.14.3/libmilter/listener.c	2008-06-18 16:36:38.000000000 +0100
f67e08
@@ -728,6 +728,7 @@
f67e08
 	int acnt = 0;	/* error count for accept() failures */
f67e08
 	int scnt = 0;	/* error count for select() failures */
f67e08
 	int save_errno = 0;
f67e08
+	int fdflags;
f67e08
 #if !_FFR_WORKERS_POOL
f67e08
 	sthread_t thread_id;
f67e08
 #endif /* !_FFR_WORKERS_POOL */
f67e08
@@ -807,6 +808,19 @@
f67e08
 		(void) smutex_unlock(&L_Mutex);
f67e08
 
f67e08
 		/*
f67e08
+		** Need to set close-on-exec for connfd in case a user's
f67e08
+		** filter starts other applications
f67e08
+		*/
f67e08
+		if ((fdflags = fcntl(connfd, F_GETFD, 0)) == -1 ||
f67e08
+		    fcntl(connfd, F_SETFD, fdflags | FD_CLOEXEC) == -1)
f67e08
+		{
f67e08
+			smi_log(SMI_LOG_WARN,
f67e08
+				"%s: Unable to set close-on-exec on connfd (%s)",
f67e08
+				smfi->xxfi_name, sm_errstring(errno));
f67e08
+			/* XXX: continue? */
f67e08
+		}
f67e08
+
f67e08
+		/*
f67e08
 		**  If remote side closes before accept() finishes,
f67e08
 		**  sockaddr might not be fully filled in.
f67e08
 		*/