Callouts: filter smtp response for bad chars before using in our smtp response. ...
authorJeremy Harris <jgh146exb@wizmail.org>
Sat, 3 Aug 2019 21:22:58 +0000 (22:22 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Sat, 3 Aug 2019 21:22:58 +0000 (22:22 +0100)
doc/doc-txt/ChangeLog
src/src/verify.c
test/log/0227
test/rejectlog/0227
test/scripts/0000-Basic/0227
test/stderr/0227
test/stdout/0227

index 9af9a9759aa9b9c57ade3e8dc8ef21296cedcc12..7fca99b620413ab5538c3a71e38dc10597e18c4b 100644 (file)
@@ -161,6 +161,9 @@ JH/34 Fix crash after TLS shutdown.  When the TCP/SMTP channel was left open,
       an attempt to use a TLS library read routine dereffed a nul pointer,
       causing a segfault.
 
       an attempt to use a TLS library read routine dereffed a nul pointer,
       causing a segfault.
 
+JH/35 Bug 2409: filter out-of-spec chars from callout response before using
+      them in our smtp response.
+
 
 Exim version 4.92
 -----------------
 
 Exim version 4.92
 -----------------
index 4422b4ad109bed885ca8063ab25c4db237f289b9..60579668bc0cc173f6766d7f4afd6ea1549142df 100644 (file)
@@ -1001,6 +1001,26 @@ no_conn:
          string_sprintf("response to \"%s\" was: %s",
                          big_buffer, string_printing(sx.buffer));
 
          string_sprintf("response to \"%s\" was: %s",
                          big_buffer, string_printing(sx.buffer));
 
+       /* RFC 5321 section 4.2: the text portion of the response may have only
+       HT, SP, Printable US-ASCII.  Deal with awkward chars by cutting the
+       received message off before passing it onward.  Newlines are ok; they
+       just become a multiline response (but wrapped in the error code we
+       produce). */
+
+       for (uschar * s = sx.buffer;
+            *s && s < sx.buffer + sizeof(sx.buffer);
+            s++)
+         {
+         uschar c = *s;
+         if (c != '\t' && c != '\n' && (c < ' ' || c > '~'))
+           {
+           if (s - sx.buffer < sizeof(sx.buffer) - 12)
+             memcpy(s, "(truncated)", 12);
+           else
+             *s = '\0';
+           break;
+           }
+         }
        addr->user_message = options & vopt_is_recipient
          ? string_sprintf("Callout verification failed:\n%s", sx.buffer)
          : string_sprintf("Called:   %s\nSent:     %s\nResponse: %s",
        addr->user_message = options & vopt_is_recipient
          ? string_sprintf("Callout verification failed:\n%s", sx.buffer)
          : string_sprintf("Called:   %s\nSent:     %s\nResponse: %s",
index eeabf702c84ab95d7c417bfa353e4dd7490cf528..4ca892aa070d5dd0039771786c627b553307f929 100644 (file)
@@ -6,8 +6,11 @@
 1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root F=<uncheckable2@localhost1> rejected RCPT <z@test.ex>: Sender verify failed
 1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root sender verify fail for <uncheckable@localhost1>: 127.0.0.1 [127.0.0.1] : response to "MAIL FROM:<>" was: 550-Multiline error for <>\n550 Here's the second line
 1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root F=<uncheckable@localhost1> rejected RCPT <z@test.ex>: Sender verify failed
 1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root F=<uncheckable2@localhost1> rejected RCPT <z@test.ex>: Sender verify failed
 1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root sender verify fail for <uncheckable@localhost1>: 127.0.0.1 [127.0.0.1] : response to "MAIL FROM:<>" was: 550-Multiline error for <>\n550 Here's the second line
 1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root F=<uncheckable@localhost1> rejected RCPT <z@test.ex>: Sender verify failed
+1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root sender verify fail for <uncheckable2@localhost1>: 127.0.0.1 [127.0.0.1] : response to "MAIL FROM:<>" was: 550 Bad-char error for <> topbitchar:\200\377\377
+1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root F=<uncheckable2@localhost1> rejected RCPT <z@test.ex>: Sender verify failed
 1999-03-02 09:44:33 H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> rejected RCPT <z@remote.domain>: 127.0.0.1 [127.0.0.1] : SMTP error from remote mail server after RCPT TO:<z@remote.domain>: 550 Recipient not liked
 1999-03-02 09:44:33 H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> rejected RCPT <z@remote.domain>: 127.0.0.1 [127.0.0.1] : SMTP error from remote mail server after RCPT TO:<z@remote.domain>: 550-Recipient not liked on two lines\n550 Here's the second
 1999-03-02 09:44:33 H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> rejected RCPT <z@remote.domain>: 127.0.0.1 [127.0.0.1] : SMTP error from remote mail server after RCPT TO:<z@remote.domain>: 550 Recipient not liked
 1999-03-02 09:44:33 H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> rejected RCPT <z@remote.domain>: 127.0.0.1 [127.0.0.1] : SMTP error from remote mail server after RCPT TO:<z@remote.domain>: 550-Recipient not liked on two lines\n550 Here's the second
+1999-03-02 09:44:33 H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> rejected RCPT <z@remote.domain>: 127.0.0.1 [127.0.0.1] : SMTP error from remote mail server after RCPT TO:<z@remote.domain>: 550 Recipient not liked, with bad char:\200\377\377
 1999-03-02 09:44:33 H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> temporarily rejected RCPT <z@remote.domain>: Could not complete recipient verify callout
 1999-03-02 09:44:33 10HmaX-0005vi-00 H=[V4NET.0.0.4] U=root F=<uncheckable@localhost1> rejected after DATA: there is no valid sender in any header line
 1999-03-02 09:44:33 10HmaY-0005vi-00 H=[V4NET.0.0.4] U=root F=<uncheckable@localhost1> rejected after DATA: there is no valid sender in any header line
 1999-03-02 09:44:33 H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> temporarily rejected RCPT <z@remote.domain>: Could not complete recipient verify callout
 1999-03-02 09:44:33 10HmaX-0005vi-00 H=[V4NET.0.0.4] U=root F=<uncheckable@localhost1> rejected after DATA: there is no valid sender in any header line
 1999-03-02 09:44:33 10HmaY-0005vi-00 H=[V4NET.0.0.4] U=root F=<uncheckable@localhost1> rejected after DATA: there is no valid sender in any header line
index da5adfc849b54534c1a8c7c9e36d75313e4a49d7..f24b9c151e72cabdbbae06a92ca7c6946aa96936 100644 (file)
@@ -6,8 +6,11 @@
 1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root F=<uncheckable2@localhost1> rejected RCPT <z@test.ex>: Sender verify failed
 1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root sender verify fail for <uncheckable@localhost1>: 127.0.0.1 [127.0.0.1] : response to "MAIL FROM:<>" was: 550-Multiline error for <>\n550 Here's the second line
 1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root F=<uncheckable@localhost1> rejected RCPT <z@test.ex>: Sender verify failed
 1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root F=<uncheckable2@localhost1> rejected RCPT <z@test.ex>: Sender verify failed
 1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root sender verify fail for <uncheckable@localhost1>: 127.0.0.1 [127.0.0.1] : response to "MAIL FROM:<>" was: 550-Multiline error for <>\n550 Here's the second line
 1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root F=<uncheckable@localhost1> rejected RCPT <z@test.ex>: Sender verify failed
+1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root sender verify fail for <uncheckable2@localhost1>: 127.0.0.1 [127.0.0.1] : response to "MAIL FROM:<>" was: 550 Bad-char error for <> topbitchar:\200\377\377
+1999-03-02 09:44:33 H=[V4NET.0.0.1] U=root F=<uncheckable2@localhost1> rejected RCPT <z@test.ex>: Sender verify failed
 1999-03-02 09:44:33 H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> rejected RCPT <z@remote.domain>: 127.0.0.1 [127.0.0.1] : SMTP error from remote mail server after RCPT TO:<z@remote.domain>: 550 Recipient not liked
 1999-03-02 09:44:33 H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> rejected RCPT <z@remote.domain>: 127.0.0.1 [127.0.0.1] : SMTP error from remote mail server after RCPT TO:<z@remote.domain>: 550-Recipient not liked on two lines\n550 Here's the second
 1999-03-02 09:44:33 H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> rejected RCPT <z@remote.domain>: 127.0.0.1 [127.0.0.1] : SMTP error from remote mail server after RCPT TO:<z@remote.domain>: 550 Recipient not liked
 1999-03-02 09:44:33 H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> rejected RCPT <z@remote.domain>: 127.0.0.1 [127.0.0.1] : SMTP error from remote mail server after RCPT TO:<z@remote.domain>: 550-Recipient not liked on two lines\n550 Here's the second
+1999-03-02 09:44:33 H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> rejected RCPT <z@remote.domain>: 127.0.0.1 [127.0.0.1] : SMTP error from remote mail server after RCPT TO:<z@remote.domain>: 550 Recipient not liked, with bad char:\200\377\377
 1999-03-02 09:44:33 H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> temporarily rejected RCPT <z@remote.domain>: Could not complete recipient verify callout
 1999-03-02 09:44:33 10HmaX-0005vi-00 H=[V4NET.0.0.4] U=root F=<uncheckable@localhost1> rejected after DATA: there is no valid sender in any header line
 Envelope-from: <uncheckable@localhost1>
 1999-03-02 09:44:33 H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> temporarily rejected RCPT <z@remote.domain>: Could not complete recipient verify callout
 1999-03-02 09:44:33 10HmaX-0005vi-00 H=[V4NET.0.0.4] U=root F=<uncheckable@localhost1> rejected after DATA: there is no valid sender in any header line
 Envelope-from: <uncheckable@localhost1>
index e53c1da7ffa94b70ae800f3c3998aebc58df7cc2..ac7bcb05cb294567ab974108506d51223c80d30e 100644 (file)
@@ -83,7 +83,7 @@ MAIL FROM
 QUIT
 250 OK
 ****
 QUIT
 250 OK
 ****
-# sender, err on mailfrom
+# sender, multiline err on mailfrom
 sudo exim -v -bs -oMa V4NET.0.0.1
 MAIL FROM:<uncheckable@localhost1>
 RCPT TO:<z@test.ex>
 sudo exim -v -bs -oMa V4NET.0.0.1
 MAIL FROM:<uncheckable@localhost1>
 RCPT TO:<z@test.ex>
@@ -94,6 +94,21 @@ server PORT_S
 EHLO
 250 OK
 MAIL FROM
 EHLO
 250 OK
 MAIL FROM
+550 Bad-char error for <> topbitchar:\x80\xFF\xFF
+QUIT
+250 OK
+****
+# sender, err on mailfrom, with bad char
+sudo exim -v -bs -oMa V4NET.0.0.1
+MAIL FROM:<uncheckable2@localhost1>
+RCPT TO:<z@test.ex>
+QUIT
+****
+server PORT_S
+220 Server ready
+EHLO
+250 OK
+MAIL FROM
 250 OK
 RCPT TO
 550 Recipient not liked
 250 OK
 RCPT TO
 550 Recipient not liked
@@ -124,6 +139,23 @@ MAIL FROM:<uncheckable@localhost1>
 RCPT TO:<z@remote.domain>
 QUIT
 ****
 RCPT TO:<z@remote.domain>
 QUIT
 ****
+server PORT_S
+220 Server ready
+EHLO
+250 OK
+MAIL FROM
+250 OK
+RCPT TO
+550 Recipient not liked, with bad char:\x80\xFF\xFF
+QUIT
+250 OK
+****
+# recipient, refused, badchar in resp
+sudo exim -v -bs -oMa V4NET.0.0.3
+MAIL FROM:<uncheckable@localhost1>
+RCPT TO:<z@remote.domain>
+QUIT
+****
 # recipient, no conneect
 sudo exim -v -bs -oMa V4NET.0.0.3
 MAIL FROM:<uncheckable@localhost1>
 # recipient, no conneect
 sudo exim -v -bs -oMa V4NET.0.0.3
 MAIL FROM:<uncheckable@localhost1>
index 768c81098eed677c79a0c711314b66d769e937d9..36e6ee75d04c915ce0340fe607ceda9b31ed009f 100644 (file)
@@ -92,6 +92,23 @@ LOG: smtp_connection MAIN
   SMTP connection from root closed by QUIT
 LOG: smtp_connection MAIN
   SMTP connection from root
   SMTP connection from root closed by QUIT
 LOG: smtp_connection MAIN
   SMTP connection from root
+Connecting to 127.0.0.1 [127.0.0.1]:1224 ...  connected
+  SMTP<< 220 Server ready
+  SMTP>> EHLO myhost.test.ex
+  SMTP<< 250 OK
+  SMTP>> MAIL FROM:<>
+  SMTP<< 550 Bad-char error for <> topbitchar:\80ÿÿ
+  SMTP>> QUIT
+  SMTP<< 250 OK
+  SMTP(close)>>
+LOG: MAIN REJECT
+  H=[V4NET.0.0.1] U=root sender verify fail for <uncheckable2@localhost1>: 127.0.0.1 [127.0.0.1] : response to "MAIL FROM:<>" was: 550 Bad-char error for <> topbitchar:\200\377\377
+LOG: MAIN REJECT
+  H=[V4NET.0.0.1] U=root F=<uncheckable2@localhost1> rejected RCPT <z@test.ex>: Sender verify failed
+LOG: smtp_connection MAIN
+  SMTP connection from root closed by QUIT
+LOG: smtp_connection MAIN
+  SMTP connection from root
 Connecting to 127.0.0.1 [127.0.0.1]:1224 ...  connected
   SMTP<< 220 Server ready
   SMTP>> EHLO myhost.test.ex
 Connecting to 127.0.0.1 [127.0.0.1]:1224 ...  connected
   SMTP<< 220 Server ready
   SMTP>> EHLO myhost.test.ex
@@ -127,6 +144,23 @@ LOG: smtp_connection MAIN
   SMTP connection from root closed by QUIT
 LOG: smtp_connection MAIN
   SMTP connection from root
   SMTP connection from root closed by QUIT
 LOG: smtp_connection MAIN
   SMTP connection from root
+Connecting to 127.0.0.1 [127.0.0.1]:1224 ...  connected
+  SMTP<< 220 Server ready
+  SMTP>> EHLO myhost.test.ex
+  SMTP<< 250 OK
+  SMTP>> MAIL FROM:<>
+  SMTP<< 250 OK
+  SMTP>> RCPT TO:<z@remote.domain>
+  SMTP<< 550 Recipient not liked, with bad char:\80ÿÿ
+  SMTP>> QUIT
+  SMTP<< 250 OK
+  SMTP(close)>>
+LOG: MAIN REJECT
+  H=[V4NET.0.0.3] U=root F=<uncheckable@localhost1> rejected RCPT <z@remote.domain>: 127.0.0.1 [127.0.0.1] : SMTP error from remote mail server after RCPT TO:<z@remote.domain>: 550 Recipient not liked, with bad char:\200\377\377
+LOG: smtp_connection MAIN
+  SMTP connection from root closed by QUIT
+LOG: smtp_connection MAIN
+  SMTP connection from root
 Connecting to 127.0.0.1 [127.0.0.1]:1224 ...  failed: Connection refused
 Connecting to ip4.ip4.ip4.ip4 [ip4.ip4.ip4.ip4]:1224 ...  failed: Connection refused
 LOG: MAIN REJECT
 Connecting to 127.0.0.1 [127.0.0.1]:1224 ...  failed: Connection refused
 Connecting to ip4.ip4.ip4.ip4 [ip4.ip4.ip4.ip4]:1224 ...  failed: Connection refused
 LOG: MAIN REJECT
index 9ee7e9f546d493416db99bac97438493796bbfb5..ff5f1359b9c96085e82ad60c3731405b880cef71 100644 (file)
 221 myhost.test.ex closing connection\r
 220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000\r
 250 OK\r
 221 myhost.test.ex closing connection\r
 220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000\r
 250 OK\r
+550 Sender verify failed\r
+221 myhost.test.ex closing connection\r
+220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000\r
+250 OK\r
 550-Callout verification failed:\r
 550 550 Recipient not liked\r
 221 myhost.test.ex closing connection\r
 550-Callout verification failed:\r
 550 550 Recipient not liked\r
 221 myhost.test.ex closing connection\r
 221 myhost.test.ex closing connection\r
 220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000\r
 250 OK\r
 221 myhost.test.ex closing connection\r
 220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000\r
 250 OK\r
+550-Callout verification failed:\r
+550 550 Recipient not liked, with bad char:(truncated)\r
+221 myhost.test.ex closing connection\r
+220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000\r
+250 OK\r
 451 Could not complete recipient verify callout\r
 221 myhost.test.ex closing connection\r
 220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000\r
 451 Could not complete recipient verify callout\r
 221 myhost.test.ex closing connection\r
 220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000\r
@@ -192,6 +201,16 @@ Connection request from [127.0.0.1]
 EHLO myhost.test.ex
 250 OK
 MAIL FROM:<>
 EHLO myhost.test.ex
 250 OK
 MAIL FROM:<>
+550 Bad-char error for <> topbitchar:\80ÿÿ
+QUIT
+250 OK
+End of script
+Listening on port 1224 ... 
+Connection request from [127.0.0.1]
+220 Server ready
+EHLO myhost.test.ex
+250 OK
+MAIL FROM:<>
 250 OK
 RCPT TO:<z@remote.domain>
 550 Recipient not liked
 250 OK
 RCPT TO:<z@remote.domain>
 550 Recipient not liked
@@ -218,6 +237,18 @@ EHLO myhost.test.ex
 250 OK
 MAIL FROM:<>
 250 OK
 250 OK
 MAIL FROM:<>
 250 OK
+RCPT TO:<z@remote.domain>
+550 Recipient not liked, with bad char:\80ÿÿ
+QUIT
+250 OK
+End of script
+Listening on port 1224 ... 
+Connection request from [127.0.0.1]
+220 Server ready
+EHLO myhost.test.ex
+250 OK
+MAIL FROM:<>
+250 OK
 RCPT TO:<abcd@x.y.z>
 550 Not liked
 QUIT
 RCPT TO:<abcd@x.y.z>
 550 Not liked
 QUIT