From c2cf0e43fcce246cb5fed11083e0575fbf490b84 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 10 Apr 2017 11:08:08 -0400 Subject: [PATCH] TT#14008 add missing DTLS locks fixes possible segfaults due to race conditions fixes #283 Change-Id: I7efba57d914163986c294b8fb1dd9531d5ef7a89 --- daemon/dtls.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/daemon/dtls.c b/daemon/dtls.c index c5f062233..5291d7960 100644 --- a/daemon/dtls.c +++ b/daemon/dtls.c @@ -674,13 +674,22 @@ int dtls(struct packet_stream *ps, const str *s, const endpoint_t *fsin) { } else if (ret == 1) { /* connected! */ + mutex_lock(&ps->out_lock); // nested lock! if (dtls_setup_crypto(ps, d)) /* XXX ?? */ ; + mutex_unlock(&ps->out_lock); + if (PS_ISSET(ps, RTP) && PS_ISSET(ps, RTCP) && ps->rtcp_sibling - && MEDIA_ISSET(ps->media, RTCP_MUX)) + && MEDIA_ISSET(ps->media, RTCP_MUX) + && ps->rtcp_sibling != ps) { + // nested locks! + mutex_lock(&ps->rtcp_sibling->in_lock); + mutex_lock(&ps->rtcp_sibling->out_lock); if (dtls_setup_crypto(ps->rtcp_sibling, d)) /* XXX ?? */ ; + mutex_unlock(&ps->rtcp_sibling->out_lock); + mutex_unlock(&ps->rtcp_sibling->in_lock); } }