<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14718">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  Friendly Automation: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pjproject: clone sdp to protect against (nat) modifications<br><br>PJSIP, UDP transport with external_media_address and session timers<br>enabled. Connected to SIP server that is not in local net. Asterisk<br>initiated the connection and is refreshing the session after 150s<br>(timeout 300s). The 2nd refresh-INVITE triggered by the pjsip timer has<br>a malformed IP address in its SDP (garbage string). This only happens<br>when the SDP is modified by the nat-code to replace the local IP address<br>with the configured external_media_address.<br>Analysis: the code to modify the SDP (in<br>res_pjsip_session.c:session_outgoing_nat_hook() and also (redundantly?)<br>in res_pjsip_sdp_rtp.c:change_outgoing_sdp_stream_media_address()) uses<br>the tdata->pool to allocate the replacement string. But the same<br>pjmedia_sdp_stream that was modified for the 1st refresh-INVITE is also<br>used for the 2nd refresh-INVITE (because it is stored in pjmedia's<br>pjmedia_sdp_neg structure). The problem is, that at that moment, the<br>tdata->pool that holds the stringified external_media_address from the<br>1. refresh-INVITE has long been reused for something else.<br>Fix by Sauw Ming of pjproject (see<br>https://github.com/pjsip/pjproject/pull/2476): the local, potentially<br>modified pjmedia_sdp_stream is cloned in<br>pjproject/source/pjsip/src/pjmedia/sip_neg.c:process_answer() and the<br>clone is stored, thereby detaching from the tdata->pool (which is only<br>released *after* process_answer())<br><br>ASTERISK-28973<br>Reported-by: Michael Neuhauser<br><br>Change-Id: I272ac22436076596e06aa51b9fa23fd1c7734a0e<br>---<br>A third-party/pjproject/patches/0060-clone-sdp-for-sip-timer-refresh-invite.patch<br>1 file changed, 28 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/third-party/pjproject/patches/0060-clone-sdp-for-sip-timer-refresh-invite.patch b/third-party/pjproject/patches/0060-clone-sdp-for-sip-timer-refresh-invite.patch</span><br><span>new file mode 100644</span><br><span>index 0000000..f1f180a</span><br><span>--- /dev/null</span><br><span>+++ b/third-party/pjproject/patches/0060-clone-sdp-for-sip-timer-refresh-invite.patch</span><br><span>@@ -0,0 +1,28 @@</span><br><span style="color: hsl(120, 100%, 40%);">+diff -ur source.orig/pjmedia/src/pjmedia/sdp_neg.c source/pjmedia/src/pjmedia/sdp_neg.c</span><br><span style="color: hsl(120, 100%, 40%);">+--- source.orig/pjmedia/src/pjmedia/sdp_neg.c    2020-07-02 10:35:42.022459904 +0200</span><br><span>++++ source/pjmedia/src/pjmedia/sdp_neg.c 2020-07-02 10:33:24.996316867 +0200</span><br><span style="color: hsl(120, 100%, 40%);">+@@ -906,7 +906,7 @@</span><br><span style="color: hsl(120, 100%, 40%);">+  * after receiving remote answer.</span><br><span style="color: hsl(120, 100%, 40%);">+  */</span><br><span style="color: hsl(120, 100%, 40%);">+ static pj_status_t process_answer(pj_pool_t *pool,</span><br><span style="color: hsl(120, 100%, 40%);">+-                                pjmedia_sdp_session *offer,</span><br><span style="color: hsl(120, 100%, 40%);">++                                  pjmedia_sdp_session *local_offer,</span><br><span style="color: hsl(120, 100%, 40%);">+                             pjmedia_sdp_session *answer,</span><br><span style="color: hsl(120, 100%, 40%);">+                                  pj_bool_t allow_asym,</span><br><span style="color: hsl(120, 100%, 40%);">+                                 pjmedia_sdp_session **p_active)</span><br><span style="color: hsl(120, 100%, 40%);">+@@ -914,10 +914,14 @@</span><br><span style="color: hsl(120, 100%, 40%);">+     unsigned omi = 0; /* Offer media index */</span><br><span style="color: hsl(120, 100%, 40%);">+     unsigned ami = 0; /* Answer media index */</span><br><span style="color: hsl(120, 100%, 40%);">+     pj_bool_t has_active = PJ_FALSE;</span><br><span style="color: hsl(120, 100%, 40%);">++    pjmedia_sdp_session *offer;</span><br><span style="color: hsl(120, 100%, 40%);">+     pj_status_t status;</span><br><span style="color: hsl(120, 100%, 40%);">+ </span><br><span style="color: hsl(120, 100%, 40%);">+     /* Check arguments. */</span><br><span style="color: hsl(120, 100%, 40%);">+-    PJ_ASSERT_RETURN(pool && offer && answer && p_active, PJ_EINVAL);</span><br><span style="color: hsl(120, 100%, 40%);">++    PJ_ASSERT_RETURN(pool && local_offer && answer && p_active, PJ_EINVAL);</span><br><span style="color: hsl(120, 100%, 40%);">++</span><br><span style="color: hsl(120, 100%, 40%);">++    /* Duplicate local offer SDP. */</span><br><span style="color: hsl(120, 100%, 40%);">++    offer = pjmedia_sdp_session_clone(pool, local_offer);</span><br><span style="color: hsl(120, 100%, 40%);">+ </span><br><span style="color: hsl(120, 100%, 40%);">+     /* Check that media count match between offer and answer */</span><br><span style="color: hsl(120, 100%, 40%);">+     // Ticket #527, different media count is allowed for more interoperability,</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14718">change 14718</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/+/14718"/><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: I272ac22436076596e06aa51b9fa23fd1c7734a0e </div>
<div style="display:none"> Gerrit-Change-Number: 14718 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Michael Neuhauser <mike@firmix.at> </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: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>