Skip to content

Commit

Permalink
lib-smtp: client: transaction: Prevent early transaction abort in smt…
Browse files Browse the repository at this point in the history
…p_client_transaction_fail_reply().

Can happen in one of the command callbacks of aborted commands.
  • Loading branch information
stephanbosch authored and sirainen committed Aug 22, 2018
1 parent 99a7c90 commit d56fd78
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib-smtp/smtp-client-private.h
Expand Up @@ -103,6 +103,7 @@ struct smtp_client_transaction {

bool data_provided:1;
bool finished:1;
bool failing:1;
bool submitted_data:1;
};

Expand Down
7 changes: 7 additions & 0 deletions src/lib-smtp/smtp-client-transaction.c
Expand Up @@ -216,6 +216,9 @@ void smtp_client_transaction_abort(struct smtp_client_transaction *trans)
struct smtp_client_transaction_rcpt **rcpts;
unsigned int i, count;

if (trans->failing)
return;

smtp_client_transaction_debug(trans, "Abort");

/* clean up */
Expand Down Expand Up @@ -313,6 +316,8 @@ void smtp_client_transaction_fail_reply(struct smtp_client_transaction *trans,
reply = trans->failure;
i_assert(reply != NULL);

trans->failing = TRUE;

smtp_client_transaction_debug(trans,
"Returning failure: %s", smtp_reply_log(reply));

Expand Down Expand Up @@ -386,6 +391,8 @@ void smtp_client_transaction_fail_reply(struct smtp_client_transaction *trans,
smtp_client_command_abort(&trans->cmd_plug);
trans->cmd_plug = NULL;

trans->failing = FALSE;

if (trans->data_provided) {
/* abort the transaction only if smtp_client_transaction_send()
was called (and if it is not aborted already) */
Expand Down

0 comments on commit d56fd78

Please sign in to comment.