File cyrus-imapd-STARTTLS-plaintext-command-injection.dif of Package cyrus-imapd

From febfa4a5e2b20521e6176c787b0f05acc05d93e6 Mon Sep 17 00:00:00 2001
From: Ken Murchison <murch@andrew.cmu.edu>
Date: Fri, 25 Mar 2011 11:50:18 -0400
Subject: Fixed bug #3423 - STARTTLS plaintext command injection vulnerability


Index: cyrus-imapd-2.3.11/imap/imapd.c
===================================================================
--- cyrus-imapd-2.3.11.orig/imap/imapd.c
+++ cyrus-imapd-2.3.11/imap/imapd.c
@@ -1689,6 +1689,9 @@ void cmdloop()
 		if (c == '\r') c = prot_getc(imapd_in);
 		if (c != '\n') goto extraargs;
 
+		/* XXX  discard any input pipelined after STARTTLS */
+		prot_flush(imapd_in);
+
 		/* if we've already done SASL fail */
 		if (imapd_userid != NULL) {
 		    prot_printf(imapd_out, 
Index: cyrus-imapd-2.3.11/imap/lmtpengine.c
===================================================================
--- cyrus-imapd-2.3.11.orig/imap/lmtpengine.c
+++ cyrus-imapd-2.3.11/imap/lmtpengine.c
@@ -1561,6 +1561,9 @@ void lmtpmode(struct lmtp_func *func,
 		sasl_ssf_t ssf;
 		char *auth_id;
 
+		/* XXX  discard any input pipelined after STARTTLS */
+		prot_flush(pin);
+
 		/* SASL and openssl have different ideas
 		   about whether ssf is signed */
 		layerp = (int *) &ssf;
Index: cyrus-imapd-2.3.11/imap/mupdate.c
===================================================================
--- cyrus-imapd-2.3.11.orig/imap/mupdate.c
+++ cyrus-imapd-2.3.11/imap/mupdate.c
@@ -909,6 +909,9 @@ mupdate_docmd_result_t docmd(struct conn
 	if (!strcmp(c->cmd.s, "Starttls")) {
 	    CHECKNEWLINE(c, ch);
 	    
+	    /* XXX  discard any input pipelined after STARTTLS */
+	    prot_flush(c->pin);
+
 	    if (!tls_enabled()) {
 		/* we don't support starttls */
 		goto badcmd;
Index: cyrus-imapd-2.3.11/imap/nntpd.c
===================================================================
--- cyrus-imapd-2.3.11.orig/imap/nntpd.c
+++ cyrus-imapd-2.3.11/imap/nntpd.c
@@ -1375,6 +1375,9 @@ static void cmdloop(void)
 		if (c == '\r') c = prot_getc(nntp_in);
 		if (c != '\n') goto extraargs;
 
+		/* XXX  discard any input pipelined after STARTTLS */
+		prot_flush(nntp_in);
+
 		cmd_starttls(0);
 	    }
 	    else if (!strcmp(cmd.s, "Stat")) {
Index: cyrus-imapd-2.3.11/imap/pop3d.c
===================================================================
--- cyrus-imapd-2.3.11.orig/imap/pop3d.c
+++ cyrus-imapd-2.3.11/imap/pop3d.c
@@ -856,6 +856,8 @@ static void cmdloop(void)
 		prot_printf(popd_out,
 			    "-ERR STLS doesn't take any arguments\r\n");
 	    } else {
+		/* XXX  discard any input pipelined after STLS */
+		prot_flush(popd_in);
 		cmd_starttls(0);
 	    }
 	}
Index: cyrus-imapd-2.3.11/imap/sync_server.c
===================================================================
--- cyrus-imapd-2.3.11.orig/imap/sync_server.c
+++ cyrus-imapd-2.3.11/imap/sync_server.c
@@ -877,6 +877,9 @@ static void cmdloop(void)
 		if (c == '\r') c = prot_getc(sync_in);
 		if (c != '\n') goto extraargs;
 
+		/* XXX  discard any input pipelined after STARTTLS */
+		prot_flush(sync_in);
+
 		/* if we've already done SASL fail */
 		if (sync_userid != NULL) {
 		    prot_printf(sync_out, 
Index: cyrus-imapd-2.3.11/lib/prot.c
===================================================================
--- cyrus-imapd-2.3.11.orig/lib/prot.c
+++ cyrus-imapd-2.3.11/lib/prot.c
@@ -553,10 +553,29 @@ int prot_fill(struct protstream *s)
 }
 
 /*
+ * If 's' is an input stream, discard any pending/buffered data.  Otherwise,
  * Write out any buffered data in the stream 's'
  */
 int prot_flush(struct protstream *s) 
 {
+    if (!s->write) {
+	int c, save_dontblock = s->dontblock;
+
+	/* Set stream to nonblocking mode */
+	if (!save_dontblock) nonblock(s->fd, (s->dontblock = 1));
+
+	/* Ingest any pending input */
+	while ((c = prot_fill(s)) != EOF);
+
+	/* Reset stream to previous blocking mode */
+	if (!save_dontblock) nonblock(s->fd, (s->dontblock = 0));
+
+	/* Discard any buffered input */
+	s->cnt = 0;
+
+	return 0;
+    }
+
     return prot_flush_internal(s, 1);
 }
 
Index: cyrus-imapd-2.3.11/timsieved/parser.c
===================================================================
--- cyrus-imapd-2.3.11.orig/timsieved/parser.c
+++ cyrus-imapd-2.3.11/timsieved/parser.c
@@ -405,6 +405,9 @@ int parser(struct protstream *sieved_out
       goto error;
     }
 
+    /* XXX  discard any input pipelined after STARTTLS */
+    prot_flush(sieved_in);
+
     if(referral_host)
 	goto do_referral;
 
openSUSE Build Service is sponsored by