]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
chan_sip: Fix segfault during module unload 94/4494/1
authorMichael Kuron <m.kuron@gmx.de>
Sat, 26 Nov 2016 16:57:03 +0000 (17:57 +0100)
committerMichael Kuron <m.kuron@gmx.de>
Sat, 26 Nov 2016 17:16:54 +0000 (18:16 +0100)
If a TCP/TLS connection was pending (not accepted and not timed out) during
unload of chan_sip, Asterisk would segfault when trying to send a signal to
a thread whose thread ID hadn't been recorded yet. This commit fixes that by
recording the thread ID before calling the blocking connect() syscall.
This was a regression introduced by 776a14386a55b5425c7e9617eff8af8b45427144.

The above wasn't enough to fix the segfault, which was now delayed to the
point where connect() timed out. Therefore, it was necessary to also remove
the SA_RESTART flag from the SIGURG sigaction so that pthread_kill() could be
used to interruput the connect() syscall.
This was a regression introduced by 5d313f51b982a18f7321adcf7c7a4e822d8b2714.

ASTERISK-26586 #close

Change-Id: I76fd9d47d56e4264e2629bce8ec15fecba673e7b

channels/chan_sip.c
main/asterisk.c

index b661f0de227ff5023155faf7181892b28699a519..8451469729354414d031e5803d4a13e58beac909 100644 (file)
@@ -2959,6 +2959,7 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s
                if (!(me = sip_threadinfo_create(tcptls_session, tcptls_session->ssl ? AST_TRANSPORT_TLS : AST_TRANSPORT_TCP))) {
                        goto cleanup;
                }
+               me->threadid = pthread_self();
                ao2_t_ref(me, +1, "Adding threadinfo ref for tcp_helper_thread");
        } else {
                struct sip_threadinfo tmp = {
@@ -2966,8 +2967,13 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s
                };
 
                if ((!(ca = tcptls_session->parent)) ||
-                       (!(me = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread"))) ||
-                       (!(tcptls_session = ast_tcptls_client_start(tcptls_session)))) {
+                       (!(me = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread")))) {
+                       goto cleanup;
+               }
+
+               me->threadid = pthread_self();
+
+               if (!(tcptls_session = ast_tcptls_client_start(tcptls_session))) {
                        goto cleanup;
                }
        }
@@ -2978,7 +2984,6 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s
                goto cleanup;
        }
 
-       me->threadid = pthread_self();
        ast_debug(2, "Starting thread for %s server\n", tcptls_session->ssl ? "TLS" : "TCP");
 
        /* set up pollfd to watch for reads on both the socket and the alert_pipe */
index fa919936b4767580ff852f2ba1fcbe7781949968..746823ef539d6ce91049fc23036b2c89826a62d8 100644 (file)
@@ -1799,7 +1799,6 @@ static void _urg_handler(int num)
 
 static struct sigaction urg_handler = {
        .sa_handler = _urg_handler,
-       .sa_flags = SA_RESTART,
 };
 
 static void _hup_handler(int num)