From dadff1d47e54962b0fdf98e8ce5cef42b6cb7fb5 Mon Sep 17 00:00:00 2001 From: "Heiko Schlittermann (HS12-RIPE)" Date: Thu, 20 Aug 2015 13:58:06 +0200 Subject: [PATCH] Fix post-transport-crash: safeguard for missing spool BUG 1671 Based on a proposal from Wolfgang Breyha. --- src/src/deliver.c | 24 ++++++++++++++++++++++-- src/src/transports/smtp.c | 17 +++++++++++------ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/src/deliver.c b/src/src/deliver.c index 0e7cea31d..b5aa9b9a7 100644 --- a/src/src/deliver.c +++ b/src/src/deliver.c @@ -9,6 +9,7 @@ #include "exim.h" +#include /* Data block for keeping track of subprocesses for parallel remote @@ -7934,17 +7935,36 @@ if (!regex_IGNOREQUOTA) regex_IGNOREQUOTA = uschar * deliver_get_sender_address (uschar * id) { +int rc; +uschar * new_sender_address, + * save_sender_address; + if (!spool_open_datafile(id)) return NULL; +/* Save and restore the global sender_address. I'm not sure if we should +not save/restore all the other global variables too, because +spool_read_header() may change all of them. But OTOH, when this +deliver_get_sender_address() gets called, the current message is done +already and nobody needs the globals anymore. (HS12, 2015-08-21) */ + sprintf(CS spoolname, "%s-H", id); -if (spool_read_header(spoolname, TRUE, TRUE) != spool_read_OK) +save_sender_address = sender_address; + +rc = spool_read_header(spoolname, TRUE, TRUE); + +new_sender_address = sender_address; +sender_address = save_sender_address; + +if (rc != spool_read_OK) return NULL; +assert(new_sender_address); + (void)close(deliver_datafile); deliver_datafile = -1; -return sender_address; +return new_sender_address; } /* vi: aw ai sw=2 diff --git a/src/src/transports/smtp.c b/src/src/transports/smtp.c index 609dba3ae..c93f2ef8f 100644 --- a/src/src/transports/smtp.c +++ b/src/src/transports/smtp.c @@ -1274,14 +1274,19 @@ we will veto this new message. */ static BOOL smtp_are_same_identities(uschar * message_id, smtp_compare_t * s_compare) { -uschar * save_sender_address = sender_address; -uschar * current_local_identity = + +uschar * message_local_identity, + * current_local_identity, + * new_sender_address; + +current_local_identity = smtp_local_identity(s_compare->current_sender_address, s_compare->tblock); -uschar * new_sender_address = deliver_get_sender_address(message_id); -uschar * message_local_identity = - smtp_local_identity(new_sender_address, s_compare->tblock); -sender_address = save_sender_address; +if (!(new_sender_address = deliver_get_sender_address(message_id))) + return 0; + +message_local_identity = + smtp_local_identity(new_sender_address, s_compare->tblock); return Ustrcmp(current_local_identity, message_local_identity) == 0; } -- 2.30.2