lkundrak / rpms / sendmail

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