bug (and possible fix) in qmail-smtputf8.patch

"Amitai Schleier" <[email protected]> 16 Aug 2017 19:14:48 +0200
Newsgroups gmane.mail.qmail.general
Message-ID <[email protected]>
[I've already corresponded directly with the patch author, who's on vacation. In the meantime, in case anyone's using the patch, I wanted to share my findings with this list.]

Arnt Gulbrandsen wrote a UTF-8 "Email Address Internationalization" patch for qmail-smtpd and qmail-remote. It was relatively recently added to the "Recommended patches" here: http://www.qmail.org/top.html#patches

I haven't noticed any problems with qmail-smtpd, but I think the patch adds a bug to qmail-remote.

To reproduce the bug:

1. Install a vanilla netqmail into /var/qmail-there

2. Apply the EAI patch, then install into /var/qmail-here

3. In /var/qmail-here/control/smtproutes, set qmail-there as qmail-here's smarthost

4. Run /var/qmail-there/bin/qmail-smtpd, wrapped in recordio

5. Run /var/qmail-here/bin/qmail-inject, sending to postmaster@qmail-there

6. Note that the message stays in qmail-here's queue

7. Inspect qmail-there's qmail-smtpd log

8. Observe that SMTP commands and message body lines are CRLF-terminated, but header lines are bare-LF-terminated

Temporarily wrapping qmail-there's qmail-smtpd with fixcrio then allows the message through.

The problem does not depend on whether the message is ASCII-only or UTF-8.

My analysis: qmail-remote.c:blast() normally munges every LF into CRLF. But when the EAI patch adds a "firstpart", those line endings don't get munged in the same way. The one-liner below munges firstpart's line endings a bit earlier. It appears to fix my bug, and maybe doesn't introduce new ones.

I trust Arnt to look at this when he returns from vacation and issue an official fix. In the meantime, perhaps this helps someone.

- Amitai


--- qmail-remote.c.orig 2017-07-30 18:24:37.000000000 +0000
+++ qmail-remote.c
@@ -253,6 +253,7 @@ void checkutf8message()
     if (r == 0) break;
     if (r == -1) temp_read();

+    if (ch == '\n' && !stralloc_append(&firstpart,"\r")) temp_nomem();
     if (!stralloc_append(&firstpart,&ch)) temp_nomem();

     if (ch == '\r')
signature.asc (application/pgp-signature, 455 B)
-----BEGIN PGP SIGNATURE-----

iQEcBAEBAgAGBQJZlH2IAAoJEPXDIAojnGOEeuQH+wd33vXrCiV/GJUSp5p8iCY1
7SrYuKMr489gFHtEA1okm841Fxmy0S80pcW4gUfYEqRTGM4M1OjVyo1AZtiGAMOB
atv3y5n7MfLc9XO1aVrWCKUMcxe3jGQ2SaW9CJRs8i3C1v+BCV5htRlzJ7OELrRl
EdsNDvz0C0HlhCe0J2Mp5MmFCzuqPUwmcl68pD6GattXd1nYHIxdl7ZOMzOvQ6vT
A8EOkSuYeEp8NwvkvhzhoRiXeZGuPSLuRW7683YDTAiaTmp1quUW/xwBRCZYtJha
s6BCchBASA70kX2mNK0REixMU/x3XNTNaK7em3JOfZ63nELGiwBPBzf4UdyJHfU=
=54dT
-----END PGP SIGNATURE-----