On Thu, Sep 19, 2019 at 05:48:17PM +0000, [email protected] wrote:

> > To me, the only real problem with '\r' is at the end of lines. It's 
> > confusing
> > since you never really know whether it's part of the content or the 
> > protocol.
> > 
> > So I suggest that we strip all '\r' found at the end of a line,
> > and retain the others.
> > 
> 
> I'm not sure the only problem is at the end of lines, but I don't think
> any solution that's graceful to bad clients will be correct so I'm okay
> with your suggestion.
> 

Here is a diff for that.
Note that it strips the '\r' on all input, not just DATA.

Eric.

Index: smtp_session.c
===================================================================
RCS file: /cvs/src/usr.sbin/smtpd/smtp_session.c,v
retrieving revision 1.414
diff -u -p -r1.414 smtp_session.c
--- smtp_session.c      3 Oct 2019 05:08:21 -0000       1.414
+++ smtp_session.c      3 Oct 2019 18:55:52 -0000
@@ -1109,14 +1109,9 @@ smtp_io(struct io *io, int evt, void *ar
                if (line == NULL)
                        return;
 
-               if (strchr(line, '\r')) {
-                       s->flags |= SF_BADINPUT;
-                       smtp_reply(s, "500 %s <CR> is only allowed before <LF>",
-                           esc_code(ESC_STATUS_PERMFAIL, ESC_OTHER_STATUS));
-                       smtp_enter_state(s, STATE_QUIT);
-                       io_set_write(io);
-                       return;
-               }
+               /* Strip trailing '\r' */
+               while (len && line[len - 1] == '\r')
+                       line[--len] = '\0';
 
                /* Message body */
                eom = 0;

Reply via email to