[exim-cvs] Fix long headers going into DSN bodies. Bug 1760

Startseite
Nachricht löschen
Nachricht beantworten
Autor: Exim Git Commits Mailing List
Datum:  
To: exim-cvs
Betreff: [exim-cvs] Fix long headers going into DSN bodies. Bug 1760
Gitweb: https://git.exim.org/exim.git/commitdiff/35d78f064b4e9f3ec28481e5e842c33a68171721
Commit:     35d78f064b4e9f3ec28481e5e842c33a68171721
Parent:     3607e3e00236f6039b765882edd0200dff6a31fc
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Thu Mar 16 19:35:48 2023 +0000
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Thu Mar 16 19:35:48 2023 +0000


    Fix long headers going into DSN bodies.  Bug 1760
---
 src/src/deliver.c     |  7 +++----
 src/src/macros.h      | 27 ++++++++++++++-------------
 src/src/transport.c   | 13 +++++++++----
 test/mail/0032.CALLER |  3 +--
 4 files changed, 27 insertions(+), 23 deletions(-)


diff --git a/src/src/deliver.c b/src/src/deliver.c
index 57a435eeb..f3a406990 100644
--- a/src/src/deliver.c
+++ b/src/src/deliver.c
@@ -5954,7 +5954,7 @@ wording. */

     tctx.u.fd = fileno(fp);
     tctx.tblock = &tb;
-    tctx.options = topt;
+    tctx.options = topt | topt_truncate_headers;
     tb.add_headers = dsnnotifyhdr;


     /*XXX no checking for failure!  buggy! */
@@ -6172,13 +6172,12 @@ fprintf(f, "--%s\n"
 fflush(f);
 /* header only as required by RFC. only failure DSN needs to honor RET=FULL */
 tctx.u.fd = fileno(f);
-tctx.options = topt_add_return_path | topt_no_body;
+tctx.options = topt_add_return_path | topt_truncate_headers | topt_no_body;
 transport_filter_argv = NULL;   /* Just in case */
 return_path = sender_address;   /* In case not previously set */


/* Write the original email out */
/*XXX no checking for failure! buggy! */
-/*XXX overlong headers in the original become overlong body lines here*/
transport_write_message(&tctx, 0);
fflush(f);

@@ -6334,7 +6333,7 @@ if (addr_senddsn)
     /* Write the original email out */


     tctx.u.fd = fd;
-    tctx.options = topt_add_return_path | topt_no_body;
+    tctx.options = topt_add_return_path | topt_truncate_headers | topt_no_body;
     /*XXX hmm, FALSE(fail) retval ignored.
     Could error for any number of reasons, and they are not handled. */
     transport_write_message(&tctx, 0);
diff --git a/src/src/macros.h b/src/src/macros.h
index 9f3a7b06a..73c6ac2c6 100644
--- a/src/src/macros.h
+++ b/src/src/macros.h
@@ -868,19 +868,20 @@ enum {


/* Options for transport_write_message */

-#define topt_add_return_path    0x0001
-#define topt_add_delivery_date  0x0002
-#define topt_add_envelope_to    0x0004
-#define topt_escape_headers     0x0008    /* Apply escape check to headers */
-#define topt_use_crlf           0x0010    /* Terminate lines with CRLF */
-#define topt_no_headers         0x0020    /* Omit headers */
-#define topt_no_body            0x0040    /* Omit body */
-#define topt_end_dot            0x0080    /* Send terminating dot line */
-#define topt_no_flush        0x0100    /* more data expected after message (eg QUIT) */
-#define topt_use_bdat        0x0200    /* prepend chunks with RFC3030 BDAT header */
-#define topt_output_string    0x0400    /* create string rather than write to fd */
-#define topt_continuation    0x0800    /* do not reset buffer */
-#define topt_not_socket        0x1000    /* cannot do socket-only syscalls */
+#define topt_add_return_path    BIT(0)
+#define topt_add_delivery_date  BIT(1)
+#define topt_add_envelope_to    BIT(2)
+#define topt_escape_headers     BIT(3)    /* Apply escape check to headers */
+#define topt_truncate_headers   BIT(4)    /* Truncate header lines at 998 chars */
+#define topt_use_crlf           BIT(5)    /* Terminate lines with CRLF */
+#define topt_no_headers         BIT(6)    /* Omit headers */
+#define topt_no_body            BIT(7)    /* Omit body */
+#define topt_end_dot            BIT(8)    /* Send terminating dot line */
+#define topt_no_flush        BIT(9)    /* more data expected after message (eg QUIT) */
+#define topt_use_bdat        BIT(10)    /* prepend chunks with RFC3030 BDAT header */
+#define topt_output_string    BIT(11)    /* create string rather than write to fd */
+#define topt_continuation    BIT(12)    /* do not reset buffer */
+#define topt_not_socket        BIT(13)    /* cannot do socket-only syscalls */


/* Options for smtp_write_command */

diff --git a/src/src/transport.c b/src/src/transport.c
index d6cedf911..80ba1eece 100644
--- a/src/src/transport.c
+++ b/src/src/transport.c
@@ -706,7 +706,7 @@ BOOL
transport_headers_send(transport_ctx * tctx,
BOOL (*sendfn)(transport_ctx * tctx, uschar * s, int len))
{
-const uschar *list;
+const uschar * list;
transport_instance * tblock = tctx ? tctx->tblock : NULL;
address_item * addr = tctx ? tctx->addr : NULL;

@@ -761,15 +761,18 @@ for (header_line * h = header_list; h; h = h->next) if (h->type != htype_old)

   if (include_header)
     {
+    int len;
     if (tblock && tblock->rewrite_rules)
       {
       rmark reset_point = store_mark();
-      header_line *hh;
+      header_line * hh;


       if ((hh = rewrite_header(h, NULL, NULL, tblock->rewrite_rules,
           tblock->rewrite_existflags, FALSE)))
     {
-    if (!sendfn(tctx, hh->text, hh->slen)) return FALSE;
+    len = hh->slen;
+    if (tctx->options & topt_truncate_headers && len > 998) len = 998;
+    if (!sendfn(tctx, hh->text, len)) return FALSE;
     store_reset(reset_point);
     continue;     /* With the next header line */
     }
@@ -777,7 +780,9 @@ for (header_line * h = header_list; h; h = h->next) if (h->type != htype_old)


     /* Either no rewriting rules, or it didn't get rewritten */


-    if (!sendfn(tctx, h->text, h->slen)) return FALSE;
+    len = h->slen;
+    if (tctx->options & topt_truncate_headers && len > 998) len = 998;
+    if (!sendfn(tctx, h->text, len)) return FALSE;
     }


/* Header removed */
diff --git a/test/mail/0032.CALLER b/test/mail/0032.CALLER
index 76aa97c73..9731b97e3 100644
--- a/test/mail/0032.CALLER
+++ b/test/mail/0032.CALLER
@@ -49,8 +49,7 @@ Received: from CALLER by myhost.ex with local (Exim x.yz)
Message-Id: <E10HmaX-0005vi-00@???>
From: CALLER_NAME <CALLER@???>
Date: Tue, 2 Mar 1999 09:44:33 +0000
-References: <0.ZERO.78901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.ONE.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.TWO.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.THREE.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.FOUR.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.FIVE.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.SIX.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.SEVEN.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.EIGHT.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.NINE.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.TEN.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.ELEVEN.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.TWELVE.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???>
-
+References: <0.ZERO.78901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.ONE.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.TWO.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.THREE.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.FOUR.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.FIVE.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.SIX.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.SEVEN.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.EIGHT.678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@???> <0.NIN
This is a test message.

--NNNNNNNNNN-eximdsn-MMMMMMMMMM--