]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-auth: Prevent double-disconnect
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 5 Jun 2017 09:44:06 +0000 (12:44 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 13 Mar 2018 06:58:10 +0000 (08:58 +0200)
When disconnecting, it's possible that
disconnect gets called twice by some callback,
so protect it with a boolean.

Fixes Panic: file hash.c: line 152 (hash_table_clear): assertion failed: (table->frozen == 0)

src/lib-auth/auth-server-connection.c
src/lib-auth/auth-server-connection.h

index 4a49795939d3cfd80d8f55aa9d5ad94163385a27..687ca0140946575a8941241449b639ee61f49f05 100644 (file)
@@ -348,6 +348,9 @@ auth_server_connection_remove_requests(struct auth_server_connection *conn,
 void auth_server_connection_disconnect(struct auth_server_connection *conn,
                                       const char *reason)
 {
+       if (!conn->connected)
+               return;
+       conn->connected = FALSE;
        conn->handshake_received = FALSE;
        conn->version_received = FALSE;
        conn->has_plain_mech = FALSE;
@@ -420,6 +423,7 @@ int auth_server_connection_connect(struct auth_server_connection *conn)
        const char *handshake;
        int fd;
 
+       i_assert(!conn->connected);
        i_assert(conn->fd == -1);
 
        conn->last_connect = ioloop_time;
@@ -443,6 +447,7 @@ int auth_server_connection_connect(struct auth_server_connection *conn)
        conn->io = io_add(fd, IO_READ, auth_server_connection_input, conn);
        conn->input = i_stream_create_fd(fd, AUTH_SERVER_CONN_MAX_LINE_LENGTH);
        conn->output = o_stream_create_fd(fd, (size_t)-1);
+       conn->connected = TRUE;
 
        handshake = t_strdup_printf("VERSION\t%u\t%u\nCPID\t%u\n",
                                    AUTH_CLIENT_PROTOCOL_MAJOR_VERSION,
index 623daf0bd639c8c30219dfc28d8fb6ce21d926d0..988fbfa435b88ba71673a9140bc77b74e1371c8f 100644 (file)
@@ -25,6 +25,7 @@ struct auth_server_connection {
        bool version_received:1;
        bool handshake_received:1;
        bool has_plain_mech:1;
+       bool connected:1;
 };
 
 struct auth_server_connection *