]> 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)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 22 Dec 2017 07:49:10 +0000 (09:49 +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 d3ca908890034bee4b9b3a4b8318e6c827a2a64b..265c6afb4400c179e714e9df3141803d696ce131 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 4e9c1a5c2b97829e1aa82b8ed49844a51ca5c4d3..6fb7aa098d013b69fe44b3c55503f708b63dde74 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 *