<p>Michael Neuhauser has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14621">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pjproject: clone sdp in sip timer handling to protect against NAT fixup<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>Solution: in pjproject/source/pjsip/src/pjsip-ua/sip_timer.c:timer_cb(),<br>modify a cloned copy of the pjmedia_sdp_stream, not the stored original<br>to protect it from changes (as is done in<br>pjproject/source/pjsip/src/pjsip-ua/sip_inv.c when calling<br>pjsip_create_sdp_body()).<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, 12 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/21/14621/1</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..7c367ec</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,12 @@</span><br><span style="color: hsl(120, 100%, 40%);">+diff -ur source.orig/pjsip/src/pjsip-ua/sip_timer.c source/pjsip/src/pjsip-ua/sip_timer.c</span><br><span style="color: hsl(120, 100%, 40%);">+--- source.orig/pjsip/src/pjsip-ua/sip_timer.c     2018-06-19 12:00:33.000000000 +0200</span><br><span>++++ source/pjsip/src/pjsip-ua/sip_timer.c        2020-06-30 15:55:51.501891714 +0200</span><br><span style="color: hsl(120, 100%, 40%);">+@@ -412,7 +412,7 @@</span><br><span style="color: hsl(120, 100%, 40%);">+              status = pjmedia_sdp_neg_get_neg_local(inv->neg, &offer);</span><br><span style="color: hsl(120, 100%, 40%);">+          if (status == PJ_SUCCESS) {</span><br><span style="color: hsl(120, 100%, 40%);">+               status = pjsip_create_sdp_body(tdata->pool, </span><br><span style="color: hsl(120, 100%, 40%);">+-                                      (pjmedia_sdp_session*)offer, &body);</span><br><span style="color: hsl(120, 100%, 40%);">++                                     pjmedia_sdp_session_clone(tdata->pool, offer), &body);</span><br><span style="color: hsl(120, 100%, 40%);">+                 tdata->msg->body = body;</span><br><span style="color: hsl(120, 100%, 40%);">+            }</span><br><span style="color: hsl(120, 100%, 40%);">+         }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14621">change 14621</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/+/14621"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I272ac22436076596e06aa51b9fa23fd1c7734a0e </div>
<div style="display:none"> Gerrit-Change-Number: 14621 </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-MessageType: newchange </div>