Blame SOURCES/sendmail-8.15.2-smtp-session-reuse-fix.patch

813923
diff -ru a/sendmail/deliver.c b/sendmail/deliver.c
813923
--- a/sendmail/deliver.c	2016-02-29 06:01:55.000000000 -0800
813923
+++ b/sendmail/deliver.c	2016-02-29 06:02:06.000000000 -0800
813923
@@ -6274,8 +6274,7 @@
813923
 				tlslogerr(LOG_WARNING, "client");
813923
 		}
813923
 
813923
-		SSL_free(clt_ssl);
813923
-		clt_ssl = NULL;
813923
+		SM_SSL_FREE(clt_ssl);
813923
 		return EX_SOFTWARE;
813923
 	}
813923
 	mci->mci_ssl = clt_ssl;
813923
@@ -6287,8 +6286,7 @@
813923
 		return EX_OK;
813923
 
813923
 	/* failure */
813923
-	SSL_free(clt_ssl);
813923
-	clt_ssl = NULL;
813923
+	SM_SSL_FREE(clt_ssl);
813923
 	return EX_SOFTWARE;
813923
 }
813923
 /*
813923
@@ -6309,7 +6307,7 @@
813923
 
813923
 	if (!bitset(MCIF_TLSACT, mci->mci_flags))
813923
 		return EX_OK;
813923
-	r = endtls(mci->mci_ssl, "client");
813923
+	r = endtls(&mci->mci_ssl, "client");
813923
 	mci->mci_flags &= ~MCIF_TLSACT;
813923
 	return r;
813923
 }
813923
diff -ru a/sendmail/macro.c b/sendmail/macro.c
813923
--- a/sendmail/macro.c	2016-02-29 06:01:55.000000000 -0800
813923
+++ b/sendmail/macro.c	2016-02-29 06:02:06.000000000 -0800
813923
@@ -362,6 +362,33 @@
813923
 }
813923
 
813923
 /*
813923
+**  MACTABCLEAR -- clear entire macro table
813923
+**
813923
+**	Parameters:
813923
+**		mac -- Macro table.
813923
+**
813923
+**	Returns:
813923
+**		none.
813923
+**
813923
+**	Side Effects:
813923
+**		clears entire mac structure including rpool pointer!
813923
+*/
813923
+
813923
+void
813923
+mactabclear(mac)
813923
+	MACROS_T *mac;
813923
+{
813923
+	int i;
813923
+
813923
+	if (mac->mac_rpool == NULL)
813923
+	{
813923
+		for (i = 0; i < MAXMACROID; i++)
813923
+	    		SM_FREE_CLR(mac->mac_table[i]);
813923
+	}
813923
+	memset((char *) mac, '\0', sizeof(*mac));
813923
+}
813923
+
813923
+/*
813923
 **  MACDEFINE -- bind a macro name to a value
813923
 **
813923
 **	Set a macro to a value, with fancy storage management.
813923
diff -ru a/sendmail/mci.c b/sendmail/mci.c
813923
--- a/sendmail/mci.c	2016-02-29 06:01:55.000000000 -0800
813923
+++ b/sendmail/mci.c	2016-02-29 06:02:06.000000000 -0800
813923
@@ -25,6 +25,7 @@
813923
 						  int, bool));
813923
 static bool	mci_load_persistent __P((MCI *));
813923
 static void	mci_uncache __P((MCI **, bool));
813923
+static void	mci_clear __P((MCI *));
813923
 static int	mci_lock_host_statfile __P((MCI *));
813923
 static int	mci_read_persistent __P((SM_FILE_T *, MCI *));
813923
 
813923
@@ -253,6 +254,7 @@
813923
 	SM_FREE_CLR(mci->mci_status);
813923
 	SM_FREE_CLR(mci->mci_rstatus);
813923
 	SM_FREE_CLR(mci->mci_heloname);
813923
+ 	mci_clear(mci);
813923
 	if (mci->mci_rpool != NULL)
813923
 	{
813923
 		sm_rpool_free(mci->mci_rpool);
813923
@@ -315,6 +317,41 @@
813923
 }
813923
 
813923
 /*
813923
+**  MCI_CLEAR -- clear mci
813923
+**
813923
+**	Parameters:
813923
+**		mci -- the connection to clear.
813923
+**
813923
+**	Returns:
813923
+**		none.
813923
+*/
813923
+
813923
+static void
813923
+mci_clear(mci)
813923
+	MCI *mci;
813923
+{
813923
+	if (mci == NULL)
813923
+		return;
813923
+
813923
+	mci->mci_maxsize = 0;
813923
+	mci->mci_min_by = 0;
813923
+	mci->mci_deliveries = 0;
813923
+#if SASL
813923
+	if (bitset(MCIF_AUTHACT, mci->mci_flags))
813923
+		sasl_dispose(&mci->mci_conn);
813923
+#endif
813923
+#if STARTTLS
813923
+	if (bitset(MCIF_TLSACT, mci->mci_flags) && mci->mci_ssl != NULL)
813923
+		SM_SSL_FREE(mci->mci_ssl);
813923
+#endif
813923
+
813923
+	/* which flags to preserve? */
813923
+	mci->mci_flags &= MCIF_CACHED;
813923
+	mactabclear(&mci->mci_macro);
813923
+}
813923
+
813923
+
813923
+/*
813923
 **  MCI_GET -- get information about a particular host
813923
 **
813923
 **	Parameters:
813923
@@ -419,6 +456,7 @@
813923
 			mci->mci_errno = 0;
813923
 			mci->mci_exitstat = EX_OK;
813923
 		}
813923
+	 	mci_clear(mci);
813923
 	}
813923
 
813923
 	return mci;
813923
diff -ru a/sendmail/sendmail.h b/sendmail/sendmail.h
813923
--- a/sendmail/sendmail.h	2016-02-29 06:01:55.000000000 -0800
813923
+++ b/sendmail/sendmail.h	2016-02-29 06:02:06.000000000 -0800
813923
@@ -1186,6 +1186,7 @@
813923
 #define macid(name)  macid_parse(name, NULL)
813923
 extern char	*macname __P((int));
813923
 extern char	*macvalue __P((int, ENVELOPE *));
813923
+extern void	mactabclear __P((MACROS_T *));
813923
 extern int	rscheck __P((char *, char *, char *, ENVELOPE *, int, int, char *, char *, ADDRESS *, char **));
813923
 extern int	rscap __P((char *, char *, char *, ENVELOPE *, char ***, char *, int));
813923
 extern void	setclass __P((int, char *));
813923
@@ -2002,7 +2003,15 @@
813923
 extern void	setclttls __P((bool));
813923
 extern bool	initsrvtls __P((bool));
813923
 extern int	tls_get_info __P((SSL *, bool, char *, MACROS_T *, bool));
813923
-extern int	endtls __P((SSL *, char *));
813923
+#define SM_SSL_FREE(ssl)			\
813923
+	do {					\
813923
+		if (ssl != NULL)		\
813923
+		{				\
813923
+			SSL_free(ssl);		\
813923
+			ssl = NULL;		\
813923
+		}				\
813923
+	} while (0)
813923
+extern int	endtls __P((SSL **, char *));
813923
 extern void	tlslogerr __P((int, const char *));
813923
 
813923
 
813923
diff -ru a/sendmail/srvrsmtp.c b/sendmail/srvrsmtp.c
813923
--- a/sendmail/srvrsmtp.c	2016-02-29 06:01:55.000000000 -0800
813923
+++ b/sendmail/srvrsmtp.c	2016-02-29 06:02:06.000000000 -0800
813923
@@ -2122,8 +2122,7 @@
813923
 			if (get_tls_se_options(e, srv_ssl, true) != 0)
813923
 			{
813923
 				message("454 4.3.3 TLS not available: error setting options");
813923
-				SSL_free(srv_ssl);
813923
-				srv_ssl = NULL;
813923
+				SM_SSL_FREE(srv_ssl);
813923
 				goto tls_done;
813923
 			}
813923
 
813923
@@ -2145,8 +2144,7 @@
813923
 			    SSL_set_wfd(srv_ssl, wfd) <= 0)
813923
 			{
813923
 				message("454 4.3.3 TLS not available: error set fd");
813923
-				SSL_free(srv_ssl);
813923
-				srv_ssl = NULL;
813923
+				SM_SSL_FREE(srv_ssl);
813923
 				goto tls_done;
813923
 			}
813923
 			if (!smtps)
813923
@@ -2188,8 +2186,7 @@
813923
 						tlslogerr(LOG_WARNING, "server");
813923
 				}
813923
 				tls_ok_srv = false;
813923
-				SSL_free(srv_ssl);
813923
-				srv_ssl = NULL;
813923
+				SM_SSL_FREE(srv_ssl);
813923
 
813923
 				/*
813923
 				**  according to the next draft of
813923
@@ -3416,7 +3413,7 @@
813923
 			/* shutdown TLS connection */
813923
 			if (tls_active)
813923
 			{
813923
-				(void) endtls(srv_ssl, "server");
813923
+				(void) endtls(&srv_ssl, "server");
813923
 				tls_active = false;
813923
 			}
813923
 #endif /* STARTTLS */
813923
diff -ru a/sendmail/tls.c b/sendmail/tls.c
813923
--- a/sendmail/tls.c	2016-02-29 06:01:55.000000000 -0800
813923
+++ b/sendmail/tls.c	2016-02-29 06:02:06.000000000 -0800
813923
@@ -1624,7 +1624,7 @@
813923
 **  ENDTLS -- shutdown secure connection
813923
 **
813923
 **	Parameters:
813923
-**		ssl -- SSL connection information.
813923
+**		pssl -- pointer to TLS session context
813923
 **		side -- server/client (for logging).
813923
 **
813923
 **	Returns:
813923
@@ -1632,12 +1632,16 @@
813923
 */
813923
 
813923
 int
813923
-endtls(ssl, side)
813923
-	SSL *ssl;
813923
+endtls(pssl, side)
813923
+	SSL **pssl;
813923
 	char *side;
813923
 {
813923
 	int ret = EX_OK;
813923
+	SSL *ssl;
813923
 
813923
+	SM_REQUIRE(pssl != NULL);
813923
+ 	ret = EX_OK;
813923
+	ssl = *pssl;
813923
 	if (ssl != NULL)
813923
 	{
813923
 		int r;
813923
@@ -1703,8 +1707,7 @@
813923
 			ret = EX_SOFTWARE;
813923
 		}
813923
 # endif /* !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER > 0x0090602fL */
813923
-		SSL_free(ssl);
813923
-		ssl = NULL;
813923
+		SM_SSL_FREE(*pssl);
813923
 	}
813923
 	return ret;
813923
 }