<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/17613">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_rtp_asterisk: Addressing possible rtp range issues<br><br>res/res_rtp_asterisk.c: Adding 1 to rtpstart if it is deteremined<br>that rtpstart was configured to be an odd value. Also adding a loop<br>counter to prevent a possible infinite loop when looking for a free<br>port.<br><br>ASTERISK-27406<br><br>Change-Id: I90f07deef0716da4a30206e9f849458b2dbe346b<br>---<br>M res/res_rtp_asterisk.c<br>1 file changed, 13 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c</span><br><span>index b0a7054..5fdcefe 100644</span><br><span>--- a/res/res_rtp_asterisk.c</span><br><span>+++ b/res/res_rtp_asterisk.c</span><br><span>@@ -3843,7 +3843,7 @@</span><br><span> </span><br><span> static int rtp_allocate_transport(struct ast_rtp_instance *instance, struct ast_rtp *rtp)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- int x, startplace;</span><br><span style="color: hsl(120, 100%, 40%);">+ int x, startplace, i, maxloops;</span><br><span> </span><br><span> rtp->strict_rtp_state = (strictrtp ? STRICT_RTP_CLOSED : STRICT_RTP_OPEN);</span><br><span> </span><br><span>@@ -3857,11 +3857,14 @@</span><br><span> }</span><br><span> </span><br><span> /* Now actually find a free RTP port to use */</span><br><span style="color: hsl(0, 100%, 40%);">- x = (rtpend == rtpstart) ? rtpstart : (ast_random() % (rtpend - rtpstart)) + rtpstart;</span><br><span style="color: hsl(120, 100%, 40%);">+ x = (ast_random() % (rtpend - rtpstart)) + rtpstart;</span><br><span> x = x & ~1;</span><br><span> startplace = x;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- for (;;) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Protection against infinite loops in the case there is a potential case where the loop is not broken such as an odd</span><br><span style="color: hsl(120, 100%, 40%);">+ start port sneaking in (even though this condition is checked at load.) */</span><br><span style="color: hsl(120, 100%, 40%);">+ maxloops = rtpend - rtpstart;</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i <= maxloops; i++) {</span><br><span> ast_sockaddr_set_port(&rtp->bind_address, x);</span><br><span> /* Try to bind, this will tell us whether the port is available or not */</span><br><span> if (!ast_bind(rtp->s, &rtp->bind_address)) {</span><br><span>@@ -9703,6 +9706,13 @@</span><br><span> </span><br><span> ast_config_destroy(cfg);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Choosing an odd start port casues issues (like a potential infinite loop) and as odd parts are not</span><br><span style="color: hsl(120, 100%, 40%);">+ chosen anyway, we are going to round up and issue a warning */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rtpstart & 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ rtpstart++;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Odd start value for RTP port in rtp.conf, rounding up to %d\n", rtpstart);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (rtpstart >= rtpend) {</span><br><span> ast_log(LOG_WARNING, "Unreasonable values for RTP start/end port in rtp.conf\n");</span><br><span> rtpstart = DEFAULT_RTP_START;</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/17613">change 17613</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/+/17613"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I90f07deef0716da4a30206e9f849458b2dbe346b </div>
<div style="display:none"> Gerrit-Change-Number: 17613 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Michael Bradeen <mbradeen@sangoma.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: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>