From b1b05573117d62c3b95d854d8ac5a447df19e82e Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Thu, 4 Oct 2012 22:21:09 +0100 Subject: [PATCH 1/1] Strip leading/trailing newlines on list of headers for addition; bug 884. NB: this means a bare "X-ACL-Warn:" header is harder to add. --- doc/doc-docbook/spec.xfpt | 4 +++- doc/doc-txt/ChangeLog | 3 +++ src/src/acl.c | 7 +++++-- test/confs/0496 | 4 +++- test/mail/0496.someone | 3 +++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt index d35c305c8..5961c4bd4 100644 --- a/doc/doc-docbook/spec.xfpt +++ b/doc/doc-docbook/spec.xfpt @@ -27320,7 +27320,9 @@ receiving a message). The message must ultimately be accepted for any ACL verb, including &%deny%& (though this is potentially useful only in a RCPT ACL). -If the data for the &%add_header%& modifier contains one or more newlines that +Leading and trailing newlines are removed from +the data for the &%add_header%& modifier; if it then +contains one or more newlines that are not followed by a space or a tab, it is assumed to contain multiple header lines. Each one is checked for valid syntax; &`X-ACL-Warn:`& is added to the front of any line that is not a valid header line. diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog index a4c10d13a..6e91c1070 100644 --- a/doc/doc-txt/ChangeLog +++ b/doc/doc-txt/ChangeLog @@ -71,6 +71,9 @@ JH/06 Add dnsdb pseudo-lookup "a+" to do an "aaaa" + "a" combination. JH/07 Avoid using a waiting database for a single-message-only transport. Performance patch from Paul Fisher. Bugzilla 1262. +JH/08 Strip leading/trailing newlines from add_header ACL modifier data. + Bugzilla 884. + Exim version 4.80 ----------------- diff --git a/src/src/acl.c b/src/src/acl.c index 3b23a915b..f9a32d3b7 100644 --- a/src/src/acl.c +++ b/src/src/acl.c @@ -958,10 +958,13 @@ setup_header(uschar *hstring) uschar *p, *q; int hlen = Ustrlen(hstring); -/* An empty string does nothing; otherwise add a final newline if necessary. */ +/* Ignore any leading newlines */ +while (*hstring == '\n') hstring++, hlen--; +/* An empty string does nothing; ensure exactly one final newline. */ if (hlen <= 0) return; -if (hstring[hlen-1] != '\n') hstring = string_sprintf("%s\n", hstring); +if (hstring[--hlen] != '\n') hstring = string_sprintf("%s\n", hstring); +else while(hstring[--hlen] == '\n') hstring[hlen+1] = '\0'; /* Loop for multiple header lines, taking care about continuations */ diff --git a/test/confs/0496 b/test/confs/0496 index 4bc2fde19..89375b11d 100644 --- a/test/confs/0496 +++ b/test/confs/0496 @@ -19,10 +19,12 @@ acl_smtp_rcpt = check_rcpt begin acl check_rcpt: - warn message = data1 data1\ndata2 data2 + warn message = data1 data1\ndata2 data2\n + warn message = \n\ndata3\n\ndata4\n\n warn message = :after_received:After-Received: some text\n\ :at_start:At-Start: some text\n\ :at_end: At-End: some text + warn message = data4 accept diff --git a/test/mail/0496.someone b/test/mail/0496.someone index 49cda3694..263f59686 100644 --- a/test/mail/0496.someone +++ b/test/mail/0496.someone @@ -12,6 +12,9 @@ Sender: CALLER_NAME Date: Tue, 2 Mar 1999 09:44:33 +0000 X-ACL-Warn: data1 data1 X-ACL-Warn: data2 data2 +X-ACL-Warn: data3 +X-ACL-Warn: +X-ACL-Warn: data4 At-End: some text Testing message -- 2.30.2