patch against NUL chars

Dmitry Alyabyev gw-cyrus at news.kiev.sovam.com
Thu May 15 08:28:02 EDT 2003


Igor Brezac wrote:

> 
> On Thu, 8 May 2003, Dmitry Alyabyev wrote:
> 
>> Hello,
>>
>> Is there a patch for cyrus 2.2 to filter out NUL chars in incoming messages
>> instead of reject them with note "Message contains NUL chars" ?
> 
> MTA can (should, well mail client should not insert nuls to start with)
> do this for you.  If you use sendmail, add '1' to the cyrus mailer flags.
> I am not familiar with other MTAs, but I believe exim can do this as well.

Okay, I have tried the case and set up exim filtering of NUL-chars *but* still
see these rejections.
And after looking into cyrus I found the problem.

imap/spool.c:
...
int spool_copy_msg(struct protstream *fin, FILE *fout, unsigned long *lines)
{
    char buf[8192], *p;
    int r = 0;
    unsigned long n = 0;

    /* -2: Might need room to add a \r\n\0 set */
    while (prot_fgets(buf, sizeof(buf)-2, fin)) {
        p = buf + strlen(buf) - 1;
        if (p < buf) {
            /* buffer start with a \0 */
            r = IMAP_MESSAGE_CONTAINSNULL;
            continue; /* need to eat the rest of the message */
        }
...
        else if (p[0] != '\n') {
            /* line contained a \0 not at the end */
            r = IMAP_MESSAGE_CONTAINSNULL;
            continue;
        }

So, if the message contains long (more than 8192 bytes) line the last block
*will* produce such error message

According to RFC-2822 such long lines are prohibited:
> 2.1.1. Line Length Limits
>
> There are two limits that this standard places on the number of characters in
> a line. Each line of characters MUST be no more than 998 characters, and
> SHOULD be no more than 78 characters, excluding the CRLF.

... but I still like to put these weak messages into mailboxes without noise :)
and this is not so trivial as filter out NUL chars on exim

Any ideas ?

-- 
Dimitry





More information about the Info-cyrus mailing list