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

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