<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16196">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Friendly Automation: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">AST-2021-008 - chan_iax2: remote crash on unsupported media format<br><br>If chan_iax2 received a packet with an unsupported media format, for<br>example vp9, then it would set the frame's format to NULL. This could<br>then result in a crash later when an attempt was made to access the<br>format.<br><br>This patch makes it so chan_iax2 now ignores/drops frames received<br>with unsupported media format types.<br><br>ASTERISK-29392 #close<br><br>Change-Id: Ifa869a90dafe33eed8fd9463574fe6f1c0ad3eb1<br>---<br>M channels/chan_iax2.c<br>1 file changed, 31 insertions(+), 9 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c</span><br><span>index 81bdf15..0ff4be9 100644</span><br><span>--- a/channels/chan_iax2.c</span><br><span>+++ b/channels/chan_iax2.c</span><br><span>@@ -4157,6 +4157,7 @@</span><br><span> long ms;</span><br><span> long next;</span><br><span> struct timeval now = ast_tvnow();</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_format *voicefmt;</span><br><span> </span><br><span> /* Make sure we have a valid private structure before going on */</span><br><span> ast_mutex_lock(&iaxsl[callno]);</span><br><span>@@ -4176,10 +4177,9 @@</span><br><span> </span><br><span> ms = ast_tvdiff_ms(now, pvt->rxcore);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if(ms >= (next = jb_next(pvt->jb))) {</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_format *voicefmt;</span><br><span style="color: hsl(0, 100%, 40%);">- voicefmt = ast_format_compatibility_bitfield2format(pvt->voiceformat);</span><br><span style="color: hsl(0, 100%, 40%);">- ret = jb_get(pvt->jb, &frame, ms, voicefmt ? ast_format_get_default_ms(voicefmt) : 20);</span><br><span style="color: hsl(120, 100%, 40%);">+ voicefmt = ast_format_compatibility_bitfield2format(pvt->voiceformat);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (voicefmt && ms >= (next = jb_next(pvt->jb))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ret = jb_get(pvt->jb, &frame, ms, ast_format_get_default_ms(voicefmt));</span><br><span> switch(ret) {</span><br><span> case JB_OK:</span><br><span> fr = frame.data;</span><br><span>@@ -4207,7 +4207,7 @@</span><br><span> pvt = iaxs[callno];</span><br><span> }</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- break;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span> case JB_DROP:</span><br><span> iax2_frame_free(frame.data);</span><br><span> break;</span><br><span>@@ -6467,8 +6467,14 @@</span><br><span> f->frametype = fh->type;</span><br><span> if (f->frametype == AST_FRAME_VIDEO) {</span><br><span> f->subclass.format = ast_format_compatibility_bitfield2format(uncompress_subclass(fh->csub & ~0x40) | ((fh->csub >> 6) & 0x1));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!f->subclass.format) {</span><br><span style="color: hsl(120, 100%, 40%);">+ f->subclass.format = ast_format_none;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> } else if (f->frametype == AST_FRAME_VOICE) {</span><br><span> f->subclass.format = ast_format_compatibility_bitfield2format(uncompress_subclass(fh->csub));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!f->subclass.format) {</span><br><span style="color: hsl(120, 100%, 40%);">+ f->subclass.format = ast_format_none;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> } else {</span><br><span> f->subclass.integer = uncompress_subclass(fh->csub);</span><br><span> }</span><br><span>@@ -9940,8 +9946,8 @@</span><br><span> } else if (iaxs[fr->callno]->voiceformat == 0) {</span><br><span> ast_log(LOG_WARNING, "Received trunked frame before first full voice frame\n");</span><br><span> iax2_vnak(fr->callno);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- f.subclass.format = ast_format_compatibility_bitfield2format(iaxs[fr->callno]->voiceformat);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if ((f.subclass.format = ast_format_compatibility_bitfield2format(</span><br><span style="color: hsl(120, 100%, 40%);">+ iaxs[fr->callno]->voiceformat))) {</span><br><span> f.datalen = len;</span><br><span> if (f.datalen >= 0) {</span><br><span> if (f.datalen)</span><br><span>@@ -10184,11 +10190,17 @@</span><br><span> f.frametype = fh->type;</span><br><span> if (f.frametype == AST_FRAME_VIDEO) {</span><br><span> f.subclass.format = ast_format_compatibility_bitfield2format(uncompress_subclass(fh->csub & ~0x40));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!f.subclass.format) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> if ((fh->csub >> 6) & 0x1) {</span><br><span> f.subclass.frame_ending = 1;</span><br><span> }</span><br><span> } else if (f.frametype == AST_FRAME_VOICE) {</span><br><span> f.subclass.format = ast_format_compatibility_bitfield2format(uncompress_subclass(fh->csub));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!f.subclass.format) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> } else {</span><br><span> f.subclass.integer = uncompress_subclass(fh->csub);</span><br><span> }</span><br><span>@@ -11807,6 +11819,11 @@</span><br><span> f.subclass.frame_ending = 1;</span><br><span> }</span><br><span> f.subclass.format = ast_format_compatibility_bitfield2format(iaxs[fr->callno]->videoformat);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!f.subclass.format) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_variables_destroy(ies.vars);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_unlock(&iaxsl[fr->callno]);</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> } else {</span><br><span> ast_log(LOG_WARNING, "Received mini frame before first full video frame\n");</span><br><span> iax2_vnak(fr->callno);</span><br><span>@@ -11828,9 +11845,14 @@</span><br><span> } else {</span><br><span> /* A mini frame */</span><br><span> f.frametype = AST_FRAME_VOICE;</span><br><span style="color: hsl(0, 100%, 40%);">- if (iaxs[fr->callno]->voiceformat > 0)</span><br><span style="color: hsl(120, 100%, 40%);">+ if (iaxs[fr->callno]->voiceformat > 0) {</span><br><span> f.subclass.format = ast_format_compatibility_bitfield2format(iaxs[fr->callno]->voiceformat);</span><br><span style="color: hsl(0, 100%, 40%);">- else {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!f.subclass.format) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_variables_destroy(ies.vars);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_mutex_unlock(&iaxsl[fr->callno]);</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span> ast_debug(1, "Received mini frame before first full voice frame\n");</span><br><span> iax2_vnak(fr->callno);</span><br><span> ast_variables_destroy(ies.vars);</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/+/16196">change 16196</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/+/16196"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: Ifa869a90dafe33eed8fd9463574fe6f1c0ad3eb1 </div>
<div style="display:none"> Gerrit-Change-Number: 16196 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-MessageType: merged </div>