<p>Joshua Colp <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13898">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, approved; Approved for Submit
George Joseph: Looks good to me, but someone else must approve
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_session: Fixed wrong session termination<br><br>When the Asterisk receives 200 OK with invalid SDP,<br>the Asterisk/PJPROJECT terminating the session.<br>But if the channel was in the Bridge, Asterisk tries send<br>the Re-Invite before terminating the session.<br>And when the Asterisk sending the Re-Invite, it doesn't check<br>the SDP is NULL or not. This crashes the Asterisk.<br><br>Fixed it to close the session correctly if the UAS sends the<br>200 OK with wrong SDP.<br><br>ASTERISK-28743<br><br>Change-Id: Ifa864e0e125b1a7ed2f3abd4164187e1dddc56da<br>---<br>M res/res_pjsip_session.c<br>1 file changed, 23 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index a20c2ea..90fb274 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -27,6 +27,7 @@</span><br><span> #include <pjsip.h></span><br><span> #include <pjsip_ua.h></span><br><span> #include <pjlib.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <pjmedia.h></span><br><span> </span><br><span> #include "asterisk/res_pjsip.h"</span><br><span> #include "asterisk/res_pjsip_session.h"</span><br><span>@@ -3868,6 +3869,28 @@</span><br><span> }</span><br><span> }</span><br><span> } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!inv->cancelling</span><br><span style="color: hsl(120, 100%, 40%);">+ && inv->role == PJSIP_ROLE_UAC</span><br><span style="color: hsl(120, 100%, 40%);">+ && inv->state == PJSIP_INV_STATE_CONFIRMED</span><br><span style="color: hsl(120, 100%, 40%);">+ && pjmedia_sdp_neg_was_answer_remote(inv->neg)</span><br><span style="color: hsl(120, 100%, 40%);">+ && pjmedia_sdp_neg_get_state(inv->neg) == PJMEDIA_SDP_NEG_STATE_DONE</span><br><span style="color: hsl(120, 100%, 40%);">+ && (session->channel && ast_channel_hangupcause(session->channel) == AST_CAUSE_BEARERCAPABILITY_NOTAVAIL)</span><br><span style="color: hsl(120, 100%, 40%);">+ ) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * We didn't send a CANCEL but the UAS sent us the 200 OK with an invalid or unacceptable codec SDP.</span><br><span style="color: hsl(120, 100%, 40%);">+ * In this case the SDP negotiation is incomplete and PJPROJECT has already sent the ACK.</span><br><span style="color: hsl(120, 100%, 40%);">+ * So, we send the BYE with 503 status code here. And the actual hangup cause code is already set</span><br><span style="color: hsl(120, 100%, 40%);">+ * to AST_CAUSE_BEARERCAPABILITY_NOTAVAIL by the session_inv_on_media_update(), setting the 503</span><br><span style="color: hsl(120, 100%, 40%);">+ * status code doesn't affect to hangup cause code.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "Endpoint '%s(%s)': Ending session due to 200 OK with incomplete SDP negotiation. %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_object_get_id(session->endpoint),</span><br><span style="color: hsl(120, 100%, 40%);">+ session->channel ? ast_channel_name(session->channel) : "",</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_rx_data_get_info(e->body.tsx_state.src.rdata));</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_inv_end_session(session->inv_session, 503, NULL, &tdata);</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (inv->cancelling && tsx->status_code == PJSIP_SC_OK) {</span><br><span> int sdp_negotiation_done =</span><br><span> pjmedia_sdp_neg_get_state(inv->neg) == PJMEDIA_SDP_NEG_STATE_DONE;</span><br><span>@@ -3886,11 +3909,6 @@</span><br><span> * UAS sent us an invalid SDP with the 200 OK. In this case</span><br><span> * the SDP negotiation is incomplete and PJPROJECT has</span><br><span> * already sent the BYE for us because of the invalid SDP.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * 3) We didn't send a CANCEL but the UAS sent us an invalid</span><br><span style="color: hsl(0, 100%, 40%);">- * SDP with the 200 OK. In this case the SDP negotiation is</span><br><span style="color: hsl(0, 100%, 40%);">- * incomplete and PJPROJECT has already sent the BYE for us</span><br><span style="color: hsl(0, 100%, 40%);">- * because of the invalid SDP.</span><br><span> */</span><br><span> ast_test_suite_event_notify("PJSIP_SESSION_CANCELED",</span><br><span> "Endpoint: %s\r\n"</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13898">change 13898</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/13898"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 17 </div>
<div style="display:none"> Gerrit-Change-Id: Ifa864e0e125b1a7ed2f3abd4164187e1dddc56da </div>
<div style="display:none"> Gerrit-Change-Number: 13898 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: sungtae kim <pchero21@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>