From 9aaea09b0210bde37e49b2368be40b27f81d9b50 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Tue, 22 May 2018 12:13:54 +0100 Subject: [PATCH] core: unhook TLS handshake fd before calling connect callback When there are multiple addresses for a server and a TLS handshake failure occurs, the next server in the list will connect and then timeout without performing any TLS handshake. This is because irc_server_close_connection closes server->sock so the next pipe to be created reuses that fd, but the hook for the handshake fd still exists when the next connection attempt is started. The hook for network_connect_child_read_cb is never added because a hook for the reused fd number still exists. Resolve this by removing the handshake hook before calling the connect callback. --- src/core/wee-network.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/wee-network.c b/src/core/wee-network.c index d5494f1d2..e04b0dce5 100644 --- a/src/core/wee-network.c +++ b/src/core/wee-network.c @@ -1305,6 +1305,7 @@ network_connect_gnutls_handshake_fd_cb (const void *pointer, void *data, } else if (rc != GNUTLS_E_SUCCESS) { + unhook (HOOK_CONNECT(hook_connect, handshake_hook_fd)); (void) (HOOK_CONNECT(hook_connect, callback)) (hook_connect->callback_pointer, hook_connect->callback_data, @@ -1326,6 +1327,7 @@ network_connect_gnutls_handshake_fd_cb (const void *pointer, void *data, */ if (hook_connect_gnutls_verify_certificates (*HOOK_CONNECT(hook_connect, gnutls_sess)) != 0) { + unhook (HOOK_CONNECT(hook_connect, handshake_hook_fd)); (void) (HOOK_CONNECT(hook_connect, callback)) (hook_connect->callback_pointer, hook_connect->callback_data, @@ -1371,6 +1373,7 @@ network_connect_gnutls_handshake_timer_cb (const void *pointer, HOOK_CONNECT(hook_connect, handshake_hook_timer) = NULL; + unhook (HOOK_CONNECT(hook_connect, handshake_hook_fd)); (void) (HOOK_CONNECT(hook_connect, callback)) (hook_connect->callback_pointer, hook_connect->callback_data,