DKIM: Fix signing for body lines starting with a pair of dots. Bug 2284
[exim.git] / src / src / dkim_transport.c
index 28d567b035936483a111622f10dcc68bf01aa6d8..0e9c3818cddbcdbf63e44c665a5ee73f96fa1e13 100644 (file)
@@ -129,7 +129,6 @@ uschar * hdrs;
 gstring * dkim_signature;
 int hsize;
 const uschar * errstr;
-uschar * verrstr;
 BOOL rc;
 
 DEBUG(D_transport) debug_printf("dkim signing direct-mode\n");
@@ -151,8 +150,14 @@ if (!rc) return FALSE;
 
 /* Get signatures for headers plus spool data file */
 
-dkim->dot_stuffed = !!(save_options & topt_end_dot);
+#ifdef EXPERIMENTAL_ARC
+arc_sign_init();
+#endif
 
+/* The dotstuffed status of the datafile depends on whether it was stored
+in wireformat. */
+
+dkim->dot_stuffed = spool_file_wireformat;
 if (!(dkim_signature = dkim_exim_sign(deliver_datafile, SPOOL_DATA_START_OFFSET,
                                    hdrs, dkim, &errstr)))
   if (!(rc = dkt_sign_fail(dkim, &errno)))
@@ -163,12 +168,14 @@ if (!(dkim_signature = dkim_exim_sign(deliver_datafile, SPOOL_DATA_START_OFFSET,
 
 #ifdef EXPERIMENTAL_ARC
 if (dkim->arc_signspec)                        /* Prepend ARC headers */
-  if (!(dkim_signature =
-       arc_sign(dkim->arc_signspec, dkim_signature, &verrstr)))
+  {
+  uschar * e;
+  if (!(dkim_signature = arc_sign(dkim->arc_signspec, dkim_signature, &e)))
     {
-    *err = verrstr;
+    *err = e;
     return FALSE;
     }
+  }
 #endif
 
 /* Write the signature and headers into the deliver-out-buffer.  This should
@@ -264,7 +271,13 @@ if (!rc)
   goto CLEANUP;
   }
 
-/* Feed the file to the goats^W DKIM lib */
+#ifdef EXPERIMENTAL_ARC
+arc_sign_init();
+#endif
+
+/* Feed the file to the goats^W DKIM lib.  At this point the dotstuffed
+status of the file depends on the output of transport_write_message() just
+above, which should be the result of the end_dot flag in tctx->options. */
 
 dkim->dot_stuffed = !!(options & topt_end_dot);
 if (!(dkim_signature = dkim_exim_sign(dkim_fd, 0, NULL, dkim, &errstr)))