]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
*-login: Another crashfix
authorTimo Sirainen <tss@iki.fi>
Thu, 22 Mar 2012 14:03:04 +0000 (16:03 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 22 Mar 2012 14:03:04 +0000 (16:03 +0200)
src/login-common/client-common.c
src/login-common/login-proxy.c
src/login-common/main.c
src/login-common/ssl-proxy-openssl.c
src/login-common/ssl-proxy.h

index fdcd46cb7064a2212d07026a02eacaad10cc16e4..1cfabb04449a407524497f94fc45c35f5e3cc0ac 100644 (file)
@@ -297,7 +297,7 @@ static void client_start_tls(struct client *client)
        if (!client_unref(&client) || client->destroyed)
                return;
 
-       fd_ssl = ssl_proxy_alloc(client->fd, &client->ip,
+       fd_ssl = ssl_proxy_alloc(client->fd, &client->ip, client->pool,
                                 client->set, &client->ssl_proxy);
        if (fd_ssl == -1) {
                client_send_line(client, CLIENT_CMD_REPLY_BYE,
index 19d6b558d357842ed456d0ee702079d31b8ce431..22ccecac828d89e646ef2e38eb36e7b72aa0d425 100644 (file)
@@ -545,7 +545,7 @@ int login_proxy_starttls(struct login_proxy *proxy)
        io_remove(&proxy->server_io);
 
        fd = ssl_proxy_client_alloc(proxy->server_fd, &proxy->client->ip,
-                                   proxy->client->set,
+                                   proxy->client->pool, proxy->client->set,
                                    login_proxy_ssl_handshaked, proxy,
                                    &proxy->ssl_server_proxy);
        if (fd < 0) {
index 16cda879139be983569c9b96953acfbd3f88a235..542eb708c1447ed1bd5ed4a4a811ae91658f0703 100644 (file)
@@ -123,7 +123,7 @@ client_connected_finish(const struct master_service_connection *conn)
                client = client_create(conn->fd, FALSE, pool, set, other_sets,
                                       &local_ip, &conn->remote_ip);
        } else {
-               fd_ssl = ssl_proxy_alloc(conn->fd, &conn->remote_ip, set,
+               fd_ssl = ssl_proxy_alloc(conn->fd, &conn->remote_ip, pool, set,
                                         &proxy);
                if (fd_ssl == -1) {
                        net_disconnect(conn->fd);
index 9759d3dc18c09db60d64d933d4bb1dd2d1754631..2c549dfb24a6747133bec520f45c7a423e747474 100644 (file)
@@ -52,6 +52,7 @@ struct ssl_proxy {
        struct client *client;
        struct ip_addr ip;
        const struct login_settings *set;
+       pool_t set_pool;
 
        int fd_ssl, fd_plain;
        struct io *io_ssl_read, *io_ssl_write, *io_plain_read, *io_plain_write;
@@ -543,7 +544,7 @@ static void ssl_step(struct ssl_proxy *proxy)
 
 static int
 ssl_proxy_alloc_common(SSL_CTX *ssl_ctx, int fd, const struct ip_addr *ip,
-                      const struct login_settings *set,
+                      pool_t set_pool, const struct login_settings *set,
                       struct ssl_proxy **proxy_r)
 {
        struct ssl_proxy *proxy;
@@ -590,7 +591,9 @@ ssl_proxy_alloc_common(SSL_CTX *ssl_ctx, int fd, const struct ip_addr *ip,
        proxy->fd_ssl = fd;
        proxy->fd_plain = sfd[0];
        proxy->ip = *ip;
-        SSL_set_ex_data(ssl, extdata_index, proxy);
+       proxy->set_pool = set_pool;
+       pool_ref(set_pool);
+       SSL_set_ex_data(ssl, extdata_index, proxy);
 
        ssl_proxy_count++;
        DLLIST_PREPEND(&ssl_proxies, proxy);
@@ -618,24 +621,26 @@ ssl_server_context_get(const struct login_settings *set)
        return ctx;
 }
 
-int ssl_proxy_alloc(int fd, const struct ip_addr *ip,
+int ssl_proxy_alloc(int fd, const struct ip_addr *ip, pool_t set_pool,
                    const struct login_settings *set,
                    struct ssl_proxy **proxy_r)
 {
        struct ssl_server_context *ctx;
 
        ctx = ssl_server_context_get(set);
-       return ssl_proxy_alloc_common(ctx->ctx, fd, ip, set, proxy_r);
+       return ssl_proxy_alloc_common(ctx->ctx, fd, ip,
+                                     set_pool, set, proxy_r);
 }
 
-int ssl_proxy_client_alloc(int fd, struct ip_addr *ip,
+int ssl_proxy_client_alloc(int fd, struct ip_addr *ip, pool_t set_pool,
                           const struct login_settings *set,
                           ssl_handshake_callback_t *callback, void *context,
                           struct ssl_proxy **proxy_r)
 {
        int ret;
 
-       ret = ssl_proxy_alloc_common(ssl_client_ctx, fd, ip, set, proxy_r);
+       ret = ssl_proxy_alloc_common(ssl_client_ctx, fd, ip,
+                                    set_pool, set, proxy_r);
        if (ret < 0)
                return -1;
 
@@ -767,6 +772,7 @@ static void ssl_proxy_unref(struct ssl_proxy *proxy)
 
        SSL_free(proxy->ssl);
 
+       pool_unref(&proxy->set_pool);
        i_free(proxy->last_error);
        i_free(proxy);
 }
index aaa6ea313216a2cd33882408b7448a96ce9e5021..6a97183a007554d5aa022ed661bc8d803e036114 100644 (file)
@@ -13,10 +13,10 @@ typedef int ssl_handshake_callback_t(void *context);
 /* establish SSL connection with the given fd, returns a new fd which you
    must use from now on, or -1 if error occurred. Unless -1 is returned,
    the given fd must be simply forgotten. */
-int ssl_proxy_alloc(int fd, const struct ip_addr *ip,
+int ssl_proxy_alloc(int fd, const struct ip_addr *ip, pool_t set_pool,
                    const struct login_settings *set,
                    struct ssl_proxy **proxy_r);
-int ssl_proxy_client_alloc(int fd, struct ip_addr *ip,
+int ssl_proxy_client_alloc(int fd, struct ip_addr *ip, pool_t set_pool,
                           const struct login_settings *set,
                           ssl_handshake_callback_t *callback, void *context,
                           struct ssl_proxy **proxy_r);