Blame SOURCES/sendmail-8.14.3-milterfdleaks.patch

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