NUL characters in messages

Chris Stromsoe cbs at cts.ucla.edu
Sun Sep 8 11:16:12 EDT 2002


On Fri, 6 Sep 2002, Chris Stromsoe wrote:

> The attached patch adds a switch to imapd.conf named "mungecrnull".  If
> mungecrnull is true, lmtpd will convert strings of "\r\0" to "\r\n\0".
> Anything else implements the old behavior.  I'm running with various
> other patches, so the line numbers may be off.
>
> At least one version of Mac Eudora incorrectly terminates lines with
> "\r\0" in some instances.  This should work around that problem.

That was a buggy patch.  So much for fixing things without sleep.  A fixed
patch to convert \r\0 to \r\n inline is attached.

Given that cyrus doesn't accept embedded NULL characters, is there a
reason that the sendmail mailer defined in cyrusv2.mc doesn't have the "1"
(disallow NULLs) flag set?


-Chris
-------------- next part --------------
--- lmtpengine.c.orig	Sun Sep  8 02:20:05 2002
+++ lmtpengine.c	Sun Sep  8 07:12:36 2002
@@ -633,6 +633,7 @@
 {
     char buf[8192], *p;
     int r = 0;
+    int mungecrnull = config_getswitch("mungecrnull", 0);
 
     while (prot_fgets(buf, sizeof(buf)-1, fin)) {
 	p = buf + strlen(buf) - 1;
@@ -643,16 +644,26 @@
 	}
 	else if (buf[0] == '\r' && buf[1] == '\0') {
 	    /* The message contained \r\0, and fgets is confusing us. */
-	    r = IMAP_MESSAGE_CONTAINSNULL;
-	    continue; /* need to eat the rest of the message */
+	    if (mungecrnull) {	/* convert to crlf */
+		syslog(LOG_DEBUG, "ate an embedded null");
+		buf[1] = '\n';
+	    } else {		/* default */
+		r = IMAP_MESSAGE_CONTAINSNULL;
+		continue; /* need to eat the rest of the message */
+	    }
 	}
 	else if (p[0] == '\r') {
 	    /*
 	     * We were unlucky enough to get a CR just before we ran
 	     * out of buffer--put it back.
 	     */
-	    prot_ungetc('\r', fin);
-	    *p = '\0';
+	    if (mungecrnull && (&p[0] < &buf[8190])) {
+		syslog(LOG_DEBUG, "ate an embedded null");
+		p[1] = '\n';
+	    } else {
+		prot_ungetc('\r', fin);
+		*p = '\0';
+	    }
 	}
 	else if (p[0] == '\n' && p[-1] != '\r') {
 	    /* found an \n without a \r */


More information about the Info-cyrus mailing list