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

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">bridge_channel_write_frame: Check for NULL channel<br><br>There is a possibility, when bridge_channel_write_frame() is<br>called, that the bridge_channel->chan will be NULL.  The first<br>thing bridge_channel_write_frame() does though is call<br>ast_channel_is_multistream() which had no check for a NULL<br>channel and therefore caused a segfault. Since it's still<br>possible for bridge_channel_write_frame() to write the frame to<br>the other channels in the bridge, we don't want to bail before we<br>call ast_channel_is_multistream() but we can just skip the<br>multi-channel stuff.  So...<br><br>bridge_channel_write_frame() only calls ast_channel_is_multistream()<br>if bridge_channel->chan is not NULL.<br><br>As a safety measure, ast_channel_is_multistream() now returns<br>false if the supplied channel is NULL.<br><br>ASTERISK-29379<br>Reported-by: Vyrva Igor<br>Reported-by: Ross Beer<br><br>Change-Id: Idfe62dbea8c69813ecfd58e113a6620dc42352ce<br>---<br>M main/bridge_channel.c<br>M main/channel_internal_api.c<br>2 files changed, 9 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/bridge_channel.c b/main/bridge_channel.c</span><br><span>index 3c5e87b..7e058af 100644</span><br><span>--- a/main/bridge_channel.c</span><br><span>+++ b/main/bridge_channel.c</span><br><span>@@ -657,8 +657,13 @@</span><br><span> </span><br><span>   ast_bridge_channel_lock_bridge(bridge_channel);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-     /* Map the frame to the bridge. */</span><br><span style="color: hsl(0, 100%, 40%);">-      if (ast_channel_is_multistream(bridge_channel->chan)) {</span><br><span style="color: hsl(120, 100%, 40%);">+    /*</span><br><span style="color: hsl(120, 100%, 40%);">+     * Map the frame to the bridge.</span><br><span style="color: hsl(120, 100%, 40%);">+        * We need to lock the bridge_channel to make sure that bridge_channel->chan</span><br><span style="color: hsl(120, 100%, 40%);">+        * isn't NULL and keep it locked while we do multistream processing.</span><br><span style="color: hsl(120, 100%, 40%);">+       */</span><br><span style="color: hsl(120, 100%, 40%);">+   ast_bridge_channel_lock(bridge_channel);</span><br><span style="color: hsl(120, 100%, 40%);">+      if (bridge_channel->chan && ast_channel_is_multistream(bridge_channel->chan)) {</span><br><span>                unmapped_stream_num = frame->stream_num;</span><br><span>          switch (frame->frametype) {</span><br><span>               case AST_FRAME_VOICE:</span><br><span>@@ -672,12 +677,10 @@</span><br><span>                                frame->stream_num = -1;</span><br><span>                           break;</span><br><span>                       }</span><br><span style="color: hsl(0, 100%, 40%);">-                       ast_bridge_channel_lock(bridge_channel);</span><br><span>                     if (frame->stream_num < (int)AST_VECTOR_SIZE(&bridge_channel->stream_map.to_bridge)) {</span><br><span>                          frame->stream_num = AST_VECTOR_GET(</span><br><span>                                       &bridge_channel->stream_map.to_bridge, frame->stream_num);</span><br><span>                                 if (0 <= frame->stream_num) {</span><br><span style="color: hsl(0, 100%, 40%);">-                                     ast_bridge_channel_unlock(bridge_channel);</span><br><span>                                   break;</span><br><span>                               }</span><br><span>                    }</span><br><span>@@ -703,6 +706,7 @@</span><br><span>              unmapped_stream_num = -1;</span><br><span>            frame->stream_num = -1;</span><br><span>   }</span><br><span style="color: hsl(120, 100%, 40%);">+     ast_bridge_channel_unlock(bridge_channel);</span><br><span> </span><br><span>       deferred = bridge_channel->bridge->technology->write(bridge_channel->bridge, bridge_channel, frame);</span><br><span>     if (deferred) {</span><br><span>diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c</span><br><span>index fb62da5..a84534a 100644</span><br><span>--- a/main/channel_internal_api.c</span><br><span>+++ b/main/channel_internal_api.c</span><br><span>@@ -1642,7 +1642,7 @@</span><br><span> </span><br><span> int ast_channel_is_multistream(struct ast_channel *chan)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-   return (chan->tech && chan->tech->read_stream && chan->tech->write_stream);</span><br><span style="color: hsl(120, 100%, 40%);">+    return (chan && chan->tech && chan->tech->read_stream && chan->tech->write_stream);</span><br><span> }</span><br><span> </span><br><span> struct ast_channel_snapshot *ast_channel_snapshot(const struct ast_channel *chan)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15742">change 15742</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/+/15742"/><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: Idfe62dbea8c69813ecfd58e113a6620dc42352ce </div>
<div style="display:none"> Gerrit-Change-Number: 15742 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.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: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>