Fix exit on attempt to rewrite a malformed address. Bug 2903
authorJeremy Harris <jgh146exb@wizmail.org>
Tue, 12 Jul 2022 21:14:04 +0000 (22:14 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Tue, 12 Jul 2022 21:15:04 +0000 (22:15 +0100)
doc/doc-txt/ChangeLog
src/src/rewrite.c
test/confs/0471
test/log/0471
test/scripts/0000-Basic/0471
test/stderr/0471

index 02ea32aa3a61aa37c8cf098bd7add4b413b3a75a..874d725f3ce6008f458a22b1a6cef87bd3e5f318 100644 (file)
@@ -14,6 +14,11 @@ JH/02 Option default value updates:
 
 JH/03 Cache static regex pattern compilations, for use by ACLs.
 
+JH/04 Bug 2903: avoid exit on an attempt to rewrite a malformed address.
+      Make the rewrite never match and keep the logging.  Trust the
+      admin to be using verify=header-syntax (to actually reject the message).
+
+
 Exim version 4.96
 -----------------
 
index bfd78b5f11a23242d827501de5a4bddce2e25aa9..90614e626ac09571918b5406f70b5005fa638f32 100644 (file)
@@ -497,15 +497,14 @@ while (*s)
 
   if (!recipient)
     {
-    /* Handle unparesable addresses in the header. Slightly ugly because a
+    /* Log unparesable addresses in the header. Slightly ugly because a
     null output from the extract can also result from a header without an
-    address, "To: undisclosed recpients:;" being the classic case. */
+    address, "To: undisclosed recpients:;" being the classic case. Ignore
+    this one and carry on. */
 
     if ((rewrite_rules || routed_old) && Ustrcmp(errmess, "empty address") != 0)
-      {
       log_write(0, LOG_MAIN, "rewrite: %s", errmess);
-      exim_exit(EXIT_FAILURE);
-      }
+
     loop_reset_point = store_reset(loop_reset_point);
     continue;
     }
index a6b8a17ef018b1d900dfe97dd72efd6970a425e4..dcd476d4a6797f7eb879841983e1c89a8f2e122b 100644 (file)
@@ -7,7 +7,14 @@ log_selector = +received_recipients
 
 # ----- Main settings -----
 
+acl_not_smtp = check
 
+begin acl
+
+check:
+       warn    !verify = header_syntax
+               logwrite = verify header_syntax fails
+       accept
 
 # ----- Rewrite -----
 
index 7b974f7f6107d1cafa9b2c39ee7f9951c7c6ebe1..9ad2e0d6c610421f81b9c099f310b47e272c55ed 100644 (file)
@@ -2,4 +2,9 @@
 1999-03-02 09:44:33 10HmaY-0005vi-00 <= CALLER@myhost.test.ex U=CALLER P=local S=sss for r2@test.ex
 1999-03-02 09:44:33 10HmaZ-0005vi-00 <= CALLER@myhost.test.ex U=CALLER P=local S=sss for r3@test.ex
 1999-03-02 09:44:33 10HmbA-0005vi-00 rewrite: address is ridiculously long: localpart_with_256_chars_567890123456789012345678901234567890123...
+1999-03-02 09:44:33 10HmbA-0005vi-00 verify header_syntax fails
+1999-03-02 09:44:33 10HmbA-0005vi-00 <= CALLER@myhost.test.ex U=CALLER P=local S=sss for r4@test.ex
 1999-03-02 09:44:33 10HmbB-0005vi-00 <= CALLER@myhost.test.ex U=CALLER P=local S=sss for r5@test.ex
+1999-03-02 09:44:33 10HmbC-0005vi-00 rewrite: domain missing or malformed
+1999-03-02 09:44:33 10HmbC-0005vi-00 verify header_syntax fails
+1999-03-02 09:44:33 10HmbC-0005vi-00 <= CALLER@myhost.test.ex U=CALLER P=local S=sss for r6@test.ex
index 1154e78c462d2bfd3fc10175be1ac2b1d1875184..423aec16f39857bb2cc9f76df3a86f598ae89467 100644 (file)
@@ -169,11 +169,13 @@ To: localpart_with_056_chars_56789012345678901234567890123456@test.example
 exim -d -odq r3@test.ex
 To: localpart_with_236_chars_56789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456@test.example
 ****
-1
 exim -d -odq r4@test.ex
 To: localpart_with_256_chars_5678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456@test.example
 ****
 exim -d -odq r5@test.ex
 To: undisclosed recpients:;
 ****
+exim -d -odq r6@test.ex
+To: fred@
+****
 no_msglog_check
index 7e4d62809921405f7add7ce5ba1ad51c64cd9522..19058d4ff82ff8306c82fe1aa5b6d3edf1bb8832 100644 (file)
@@ -25880,6 +25880,13 @@ P Received: from CALLER by myhost.test.ex with local (Exim x.yz)
        id 10HmaX-0005vi-00
        for r1@test.ex;
        Tue, 2 Mar 1999 09:44:33 +0000
+using ACL "check"
+processing "warn" (TESTSUITE/test-config 15)
+check !verify = header_syntax
+warn: condition test failed in ACL "check"
+processing "accept" (TESTSUITE/test-config 17)
+accept: condition test succeeded in ACL "check"
+end of ACL "check": ACCEPT
 Writing spool header file: TESTSUITE/spool//input//hdr.10HmaX-0005vi-00
 DSN: **** SPOOL_OUT - address: <r1@test.ex> errorsto: <NULL> orcpt: <NULL> dsn_flags: 0x0
 Renaming spool header file: TESTSUITE/spool//input//10HmaX-0005vi-00-H
@@ -26046,6 +26053,13 @@ P Received: from CALLER by myhost.test.ex with local (Exim x.yz)
        id 10HmaY-0005vi-00
        for r2@test.ex;
        Tue, 2 Mar 1999 09:44:33 +0000
+using ACL "check"
+processing "warn" (TESTSUITE/test-config 15)
+check !verify = header_syntax
+warn: condition test failed in ACL "check"
+processing "accept" (TESTSUITE/test-config 17)
+accept: condition test succeeded in ACL "check"
+end of ACL "check": ACCEPT
 Writing spool header file: TESTSUITE/spool//input//hdr.10HmaY-0005vi-00
 DSN: **** SPOOL_OUT - address: <r2@test.ex> errorsto: <NULL> orcpt: <NULL> dsn_flags: 0x0
 Renaming spool header file: TESTSUITE/spool//input//10HmaY-0005vi-00-H
@@ -26211,6 +26225,13 @@ P Received: from CALLER by myhost.test.ex with local (Exim x.yz)
        id 10HmaZ-0005vi-00
        for r3@test.ex;
        Tue, 2 Mar 1999 09:44:33 +0000
+using ACL "check"
+processing "warn" (TESTSUITE/test-config 15)
+check !verify = header_syntax
+warn: condition test failed in ACL "check"
+processing "accept" (TESTSUITE/test-config 17)
+accept: condition test succeeded in ACL "check"
+end of ACL "check": ACCEPT
 Writing spool header file: TESTSUITE/spool//input//hdr.10HmaZ-0005vi-00
 DSN: **** SPOOL_OUT - address: <r3@test.ex> errorsto: <NULL> orcpt: <NULL> dsn_flags: 0x0
 Renaming spool header file: TESTSUITE/spool//input//10HmaZ-0005vi-00-H
@@ -26304,8 +26325,71 @@ rewrite headers
    To: localpart_with_256_chars_5678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456@test.example
 LOG: MAIN
   rewrite: address is ridiculously long: localpart_with_256_chars_567890123456789012345678901234567890123...
- search_tidyup called
->>>>>>>>>>>>>>>> Exim pid=p1237 (fresh-exec) terminating with rc=1 >>>>>>>>>>>>>>>>
+ rewrite_one_header: type=F:
+   From: CALLER_NAME <CALLER@myhost.test.ex>
+ address match test: subject=CALLER@myhost.test.ex pattern=^.{40,}@*
+ compiled RE '^.{40,}@*' found in local cache
+ CALLER@myhost.test.ex in "^.{40,}@*"? no (end of list)
+ address match test: subject=CALLER@myhost.test.ex pattern=*@*
+ myhost.test.ex in "*"? yes (matched "*")
+ CALLER@myhost.test.ex in "*@*"? yes (matched "*@*")
+  search_open: lsearch "TESTSUITE/aux-fixed/0471.rw"
+    cached open
+  search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    key="myhost.test.ex" partial=2 affix=*. starflags=0 opts=NULL
+  LRU list:
+    0TESTSUITE/aux-fixed/0471.rw
+    End
+  internal_search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    type=lsearch key="myhost.test.ex" opts=NULL
+  cached data used for lookup of myhost.test.ex
+    in TESTSUITE/aux-fixed/0471.rw
+  lookup failed
+  trying partial match *.myhost.test.ex
+  internal_search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    type=lsearch key="*.myhost.test.ex" opts=NULL
+  cached data used for lookup of *.myhost.test.ex
+    in TESTSUITE/aux-fixed/0471.rw
+  lookup failed
+  trying partial match *.test.ex
+  internal_search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    type=lsearch key="*.test.ex" opts=NULL
+  cached data used for lookup of *.test.ex
+    in TESTSUITE/aux-fixed/0471.rw
+  lookup failed
+search_tidyup called
+>>Headers after rewriting and local additions:
+T To: localpart_with_256_chars_5678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456@test.example
+I Message-Id: <E10HmbA-0005vi-00@myhost.test.ex>
+F From: CALLER_NAME <CALLER@myhost.test.ex>
+  Date: Tue, 2 Mar 1999 09:44:33 +0000
+
+Data file name: TESTSUITE/spool//input//10HmbA-0005vi-00-D
+Data file written for message 10HmbA-0005vi-00
+>>Generated Received: header line
+P Received: from CALLER by myhost.test.ex with local (Exim x.yz)
+       (envelope-from <CALLER@myhost.test.ex>)
+       id 10HmbA-0005vi-00
+       for r4@test.ex;
+       Tue, 2 Mar 1999 09:44:33 +0000
+using ACL "check"
+processing "warn" (TESTSUITE/test-config 15)
+check !verify = header_syntax
+check logwrite = verify header_syntax fails
+LOG: MAIN
+  verify header_syntax fails
+warn: condition test succeeded in ACL "check"
+processing "accept" (TESTSUITE/test-config 17)
+accept: condition test succeeded in ACL "check"
+end of ACL "check": ACCEPT
+Writing spool header file: TESTSUITE/spool//input//hdr.10HmbA-0005vi-00
+DSN: **** SPOOL_OUT - address: <r4@test.ex> errorsto: <NULL> orcpt: <NULL> dsn_flags: 0x0
+Renaming spool header file: TESTSUITE/spool//input//10HmbA-0005vi-00-H
+Size of headers = sss
+LOG: MAIN
+  <= CALLER@myhost.test.ex U=CALLER P=local S=sss
+search_tidyup called
+>>>>>>>>>>>>>>>> Exim pid=p1237 (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
 Exim version x.yz ....
 changed uid/gid: forcing real = effective
   uid=uuuu gid=CALLER_GID pid=p1238
@@ -26436,6 +26520,13 @@ P Received: from CALLER by myhost.test.ex with local (Exim x.yz)
        id 10HmbB-0005vi-00
        for r5@test.ex;
        Tue, 2 Mar 1999 09:44:33 +0000
+using ACL "check"
+processing "warn" (TESTSUITE/test-config 15)
+check !verify = header_syntax
+warn: condition test failed in ACL "check"
+processing "accept" (TESTSUITE/test-config 17)
+accept: condition test succeeded in ACL "check"
+end of ACL "check": ACCEPT
 Writing spool header file: TESTSUITE/spool//input//hdr.10HmbB-0005vi-00
 DSN: **** SPOOL_OUT - address: <r5@test.ex> errorsto: <NULL> orcpt: <NULL> dsn_flags: 0x0
 Renaming spool header file: TESTSUITE/spool//input//10HmbB-0005vi-00-H
@@ -26444,3 +26535,153 @@ LOG: MAIN
   <= CALLER@myhost.test.ex U=CALLER P=local S=sss
 search_tidyup called
 >>>>>>>>>>>>>>>> Exim pid=p1238 (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
+Exim version x.yz ....
+changed uid/gid: forcing real = effective
+  uid=uuuu gid=CALLER_GID pid=p1239
+configuration file is TESTSUITE/test-config
+admin user
+changed uid/gid: privilege not needed
+  uid=EXIM_UID gid=EXIM_GID pid=p1239
+originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME
+sender address = CALLER@myhost.test.ex
+set_process_info: pppp accepting a local non-SMTP message from <CALLER@myhost.test.ex>
+spool directory space = nnnnnK inodes = nnnnn check_space = 10240K inodes = 100 msg_size = 0
+log directory space = nnnnnK inodes = nnnnn check_space = 10240K inodes = 100
+Sender: CALLER@myhost.test.ex
+Recipients:
+  r6@test.ex
+search_tidyup called
+>>Headers received:
+To: fred@
+
+qualify & rewrite recipients list
+ address match test: subject=r6@test.ex pattern=^.{40,}@*
+ compiled RE '^.{40,}@*' not found in local cache
+ compiled RE '^.{40,}@*' saved in local cache
+ r6@test.ex in "^.{40,}@*"? no (end of list)
+ address match test: subject=r6@test.ex pattern=*@*
+ test.ex in "*"? yes (matched "*")
+ r6@test.ex in "*@*"? yes (matched "*@*")
+  search_open: lsearch "TESTSUITE/aux-fixed/0471.rw"
+  search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    key="test.ex" partial=2 affix=*. starflags=0 opts=NULL
+  LRU list:
+    0TESTSUITE/aux-fixed/0471.rw
+    End
+  internal_search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    type=lsearch key="test.ex" opts=NULL
+  file lookup required for test.ex
+    in TESTSUITE/aux-fixed/0471.rw
+  creating new cache entry
+  lookup failed
+  trying partial match *.test.ex
+  internal_search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    type=lsearch key="*.test.ex" opts=NULL
+  file lookup required for *.test.ex
+    in TESTSUITE/aux-fixed/0471.rw
+  creating new cache entry
+  lookup failed
+global rewrite rules
+ address match test: subject=CALLER@myhost.test.ex pattern=^.{40,}@*
+ compiled RE '^.{40,}@*' found in local cache
+ CALLER@myhost.test.ex in "^.{40,}@*"? no (end of list)
+ address match test: subject=CALLER@myhost.test.ex pattern=*@*
+ myhost.test.ex in "*"? yes (matched "*")
+ CALLER@myhost.test.ex in "*@*"? yes (matched "*@*")
+  search_open: lsearch "TESTSUITE/aux-fixed/0471.rw"
+    cached open
+  search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    key="myhost.test.ex" partial=2 affix=*. starflags=0 opts=NULL
+  LRU list:
+    0TESTSUITE/aux-fixed/0471.rw
+    End
+  internal_search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    type=lsearch key="myhost.test.ex" opts=NULL
+  file lookup required for myhost.test.ex
+    in TESTSUITE/aux-fixed/0471.rw
+  creating new cache entry
+  lookup failed
+  trying partial match *.myhost.test.ex
+  internal_search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    type=lsearch key="*.myhost.test.ex" opts=NULL
+  file lookup required for *.myhost.test.ex
+    in TESTSUITE/aux-fixed/0471.rw
+  creating new cache entry
+  lookup failed
+  trying partial match *.test.ex
+  internal_search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    type=lsearch key="*.test.ex" opts=NULL
+  cached data used for lookup of *.test.ex
+    in TESTSUITE/aux-fixed/0471.rw
+  lookup failed
+rewritten sender = CALLER@myhost.test.ex
+rewrite headers
+ rewrite_one_header: type=T:
+   To: fred@
+LOG: MAIN
+  rewrite: domain missing or malformed
+ rewrite_one_header: type=F:
+   From: CALLER_NAME <CALLER@myhost.test.ex>
+ address match test: subject=CALLER@myhost.test.ex pattern=^.{40,}@*
+ compiled RE '^.{40,}@*' found in local cache
+ CALLER@myhost.test.ex in "^.{40,}@*"? no (end of list)
+ address match test: subject=CALLER@myhost.test.ex pattern=*@*
+ myhost.test.ex in "*"? yes (matched "*")
+ CALLER@myhost.test.ex in "*@*"? yes (matched "*@*")
+  search_open: lsearch "TESTSUITE/aux-fixed/0471.rw"
+    cached open
+  search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    key="myhost.test.ex" partial=2 affix=*. starflags=0 opts=NULL
+  LRU list:
+    0TESTSUITE/aux-fixed/0471.rw
+    End
+  internal_search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    type=lsearch key="myhost.test.ex" opts=NULL
+  cached data used for lookup of myhost.test.ex
+    in TESTSUITE/aux-fixed/0471.rw
+  lookup failed
+  trying partial match *.myhost.test.ex
+  internal_search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    type=lsearch key="*.myhost.test.ex" opts=NULL
+  cached data used for lookup of *.myhost.test.ex
+    in TESTSUITE/aux-fixed/0471.rw
+  lookup failed
+  trying partial match *.test.ex
+  internal_search_find: file="TESTSUITE/aux-fixed/0471.rw"
+    type=lsearch key="*.test.ex" opts=NULL
+  cached data used for lookup of *.test.ex
+    in TESTSUITE/aux-fixed/0471.rw
+  lookup failed
+search_tidyup called
+>>Headers after rewriting and local additions:
+T To: fred@
+I Message-Id: <E10HmbC-0005vi-00@myhost.test.ex>
+F From: CALLER_NAME <CALLER@myhost.test.ex>
+  Date: Tue, 2 Mar 1999 09:44:33 +0000
+
+Data file name: TESTSUITE/spool//input//10HmbC-0005vi-00-D
+Data file written for message 10HmbC-0005vi-00
+>>Generated Received: header line
+P Received: from CALLER by myhost.test.ex with local (Exim x.yz)
+       (envelope-from <CALLER@myhost.test.ex>)
+       id 10HmbC-0005vi-00
+       for r6@test.ex;
+       Tue, 2 Mar 1999 09:44:33 +0000
+using ACL "check"
+processing "warn" (TESTSUITE/test-config 15)
+check !verify = header_syntax
+check logwrite = verify header_syntax fails
+LOG: MAIN
+  verify header_syntax fails
+warn: condition test succeeded in ACL "check"
+processing "accept" (TESTSUITE/test-config 17)
+accept: condition test succeeded in ACL "check"
+end of ACL "check": ACCEPT
+Writing spool header file: TESTSUITE/spool//input//hdr.10HmbC-0005vi-00
+DSN: **** SPOOL_OUT - address: <r6@test.ex> errorsto: <NULL> orcpt: <NULL> dsn_flags: 0x0
+Renaming spool header file: TESTSUITE/spool//input//10HmbC-0005vi-00-H
+Size of headers = sss
+LOG: MAIN
+  <= CALLER@myhost.test.ex U=CALLER P=local S=sss
+search_tidyup called
+>>>>>>>>>>>>>>>> Exim pid=p1239 (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>