diff options
author | Richard Mudgett <rmudgett@digium.com> | 2012-06-11 17:34:08 +0000 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2012-06-11 17:34:08 +0000 |
commit | 72eb8eb1e7ee0e097c1124a9c12cc984a670ee24 (patch) | |
tree | c5ccd4f6f09127b22eeaf49b7f37585b1e48d723 /channels/chan_sip.c | |
parent | c6142cf2cc7312122abcf74d6ab1daf0ad1d72bf (diff) |
Fix deadlock potential with ast_set_hangupsource() calls.
Calling ast_set_hangupsource() with the channel lock held can result in a
deadlock because the function also locks the bridged channel.
(issue ASTERISK-19537)
(closes issue AST-891)
Reported by: Guenther Kelleter
Tested by: Guenther Kelleter
(closes issue ASTERISK-19801)
Reported by: Alec Davis
........
Merged revisions 368759 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 368760 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@368772 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels/chan_sip.c')
-rw-r--r-- | channels/chan_sip.c | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c index d8c9f3958..934f8a611 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -20973,6 +20973,41 @@ static void handle_response_publish(struct sip_pvt *p, int resp, const char *res } } +/*! + * \internal + * \brief Set hangup source and cause. + * + * \param p SIP private. + * \param cause Hangup cause to queue. Zero if no cause. + * + * \pre p and p->owner are locked. + * + * \return Nothing + */ +static void sip_queue_hangup_cause(struct sip_pvt *p, int cause) +{ + struct ast_channel *owner = p->owner; + const char *name = ast_strdupa(ast_channel_name(owner)); + + /* Cannot hold any channel/private locks when calling. */ + ast_channel_ref(owner); + ast_channel_unlock(owner); + sip_pvt_unlock(p); + ast_set_hangupsource(owner, name, 0); + if (cause) { + ast_queue_hangup_with_cause(owner, cause); + } else { + ast_queue_hangup(owner); + } + ast_channel_unref(owner); + + /* Relock things. */ + owner = sip_pvt_lock_full(p); + if (owner) { + ast_channel_unref(owner); + } +} + /*! \brief Handle SIP response to INVITE dialogue */ static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno) { @@ -21339,16 +21374,14 @@ static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); ast_log(LOG_WARNING, "Received response: \"Forbidden\" from '%s'\n", sip_get_header(&p->initreq, "From")); if (!req->ignore && p->owner) { - ast_set_hangupsource(p->owner, ast_channel_name(p->owner), 0); - ast_queue_hangup_with_cause(p->owner, hangup_sip2cause(resp)); + sip_queue_hangup_cause(p, hangup_sip2cause(resp)); } break; case 404: /* Not found */ xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); if (p->owner && !req->ignore) { - ast_set_hangupsource(p->owner, ast_channel_name(p->owner), 0); - ast_queue_hangup_with_cause(p->owner, hangup_sip2cause(resp)); + sip_queue_hangup_cause(p, hangup_sip2cause(resp)); } break; @@ -24882,11 +24915,10 @@ static int handle_request_cancel(struct sip_pvt *p, struct sip_request *req) stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */ if (p->owner) { - ast_set_hangupsource(p->owner, ast_channel_name(p->owner), 0); - ast_queue_hangup(p->owner); - } - else + sip_queue_hangup_cause(p, 0); + } else { sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); + } if (ast_str_strlen(p->initreq.data) > 0) { struct sip_pkt *pkt, *prev_pkt; /* If the CANCEL we are receiving is a retransmission, and we already have scheduled @@ -25040,8 +25072,7 @@ static int handle_request_bye(struct sip_pvt *p, struct sip_request *req) ast_queue_hangup_with_cause(p->owner, AST_CAUSE_PROTOCOL_ERROR); } } else if (p->owner) { - ast_set_hangupsource(p->owner, ast_channel_name(p->owner), 0); - ast_queue_hangup(p->owner); + sip_queue_hangup_cause(p, 0); sip_scheddestroy_final(p, DEFAULT_TRANS_TIMEOUT); ast_debug(3, "Received bye, issuing owner hangup\n"); } else { |