From: Timo Sirainen Date: Thu, 18 May 2017 14:36:27 +0000 (+0300) Subject: lib-imap-client: Avoid infinite reconnection loops when retrying command fails X-Git-Tag: 2.3.0.rc1~1608 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e266d02220804645dae64e3939a4a677da584128;p=thirdparty%2Fdovecot%2Fcore.git lib-imap-client: Avoid infinite reconnection loops when retrying command fails reconnect_command_count wasn't calculated correctly, because the SELECT and potentially other following sync commands weren't included in it. --- diff --git a/src/lib-imap-client/imapc-client.h b/src/lib-imap-client/imapc-client.h index 54dadbdff8..03afe4f752 100644 --- a/src/lib-imap-client/imapc-client.h +++ b/src/lib-imap-client/imapc-client.h @@ -52,7 +52,9 @@ enum imapc_command_flags { finishes. */ IMAPC_COMMAND_FLAG_RETRIABLE = 0x04, /* This is the LOGOUT command. Use a small timeout for it. */ - IMAPC_COMMAND_FLAG_LOGOUT = 0x08 + IMAPC_COMMAND_FLAG_LOGOUT = 0x08, + /* Command is being resent after a reconnection. */ + IMAPC_COMMAND_FLAG_RECONNECTED = 0x10 }; enum imapc_client_ssl_mode { diff --git a/src/lib-imap-client/imapc-connection.c b/src/lib-imap-client/imapc-connection.c index 3a27241f10..48a2a6e159 100644 --- a/src/lib-imap-client/imapc-connection.c +++ b/src/lib-imap-client/imapc-connection.c @@ -300,6 +300,7 @@ imapc_connection_abort_commands_array(ARRAY_TYPE(imapc_command) *cmd_array, (cmd->flags & IMAPC_COMMAND_FLAG_RETRIABLE) != 0) { cmd->send_pos = 0; cmd->wait_for_literal = 0; + cmd->flags |= IMAPC_COMMAND_FLAG_RECONNECTED; i++; } else { array_delete(cmd_array, i, 1); @@ -1433,7 +1434,7 @@ static int imapc_connection_input_tagged(struct imapc_connection *conn) } if (conn->reconnect_command_count > 0 && - (cmd->flags & IMAPC_COMMAND_FLAG_PRELOGIN) == 0) { + (cmd->flags & IMAPC_COMMAND_FLAG_RECONNECTED) != 0) { if (--conn->reconnect_command_count == 0) { /* we've received replies for all the commands started before reconnection. if we get disconnected now, we