<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15232">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pbx_realtime: wrong type stored on publish of ast_channel_snapshot_type<br><br>A prior patch segmented channel snapshots, and changed the underlying<br>data object type associated with ast_channel_snapshot_type stasis<br>messages. Prior to Asterisk 18 it was a type ast_channel_snapshot, but<br>now it type ast_channel_snapshot_update.<br><br>When publishing ast_channel_snapshot_type in pbx_realtime the<br>ast_channel_snapshot was being passed in as the message data<br>object. When a handler, expecting a data object type of<br>ast_channel_snapshot_update, dereferenced this value a crash<br>would occur.<br><br>This patch makes it so pbx_realtime now uses the expected type, and<br>channel snapshot publish method when publishing.<br><br>ASTERISK-29168 #close<br><br>Change-Id: I9a2cfa0ec285169317f4b9146e4027da8a4fe896<br>---<br>M pbx/pbx_realtime.c<br>1 file changed, 19 insertions(+), 13 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pbx/pbx_realtime.c b/pbx/pbx_realtime.c</span><br><span>index 970bb3c..3d071a4 100644</span><br><span>--- a/pbx/pbx_realtime.c</span><br><span>+++ b/pbx/pbx_realtime.c</span><br><span>@@ -331,8 +331,6 @@</span><br><span> char tmp1[80];</span><br><span> char tmp2[80];</span><br><span> char tmp3[EXT_DATA_SIZE];</span><br><span style="color: hsl(0, 100%, 40%);">- RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);</span><br><span style="color: hsl(0, 100%, 40%);">- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);</span><br><span> </span><br><span> appdata[0] = 0; /* just in case the substitute var func isn't called */</span><br><span> if(!ast_strlen_zero(appdata_tmp))</span><br><span>@@ -343,25 +341,33 @@</span><br><span> term_color(tmp2, ast_channel_name(chan), COLOR_BRMAGENTA, 0, sizeof(tmp2)),</span><br><span> term_color(tmp3, S_OR(appdata, ""), COLOR_BRMAGENTA, 0, sizeof(tmp3)));</span><br><span> if (ast_channel_snapshot_type()) {</span><br><span style="color: hsl(120, 100%, 40%);">+ char *tmp_appl;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *tmp_data;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ast_channel_lock(chan);</span><br><span> /* Force a new dialplan segment that will be unique to use so we can update it with the</span><br><span> * information we want. In the future when a channel snapshot is published this will</span><br><span> * occur again and unset this flag.</span><br><span> */</span><br><span> ast_channel_snapshot_invalidate_segment(chan, AST_CHANNEL_SNAPSHOT_INVALIDATE_DIALPLAN);</span><br><span style="color: hsl(0, 100%, 40%);">- snapshot = ast_channel_snapshot_create(chan);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_channel_unlock(chan);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- if (snapshot) {</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* pbx_exec sets application name and data, but we don't want to log</span><br><span style="color: hsl(0, 100%, 40%);">- * every exec. Just update the snapshot here instead.</span><br><span style="color: hsl(120, 100%, 40%);">+ * every exec. Just update the snapshot here instead. Publishing the</span><br><span style="color: hsl(120, 100%, 40%);">+ * snapshot retrieves data from the channel object directly, so save</span><br><span style="color: hsl(120, 100%, 40%);">+ * current values prior to publishing so they can be restored after.</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">- ast_string_field_set(snapshot->dialplan, appl, app);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_string_field_set(snapshot->dialplan, data, !ast_strlen_zero(appdata) ? appdata : "(NULL)");</span><br><span style="color: hsl(0, 100%, 40%);">- msg = stasis_message_create(ast_channel_snapshot_type(), snapshot);</span><br><span style="color: hsl(0, 100%, 40%);">- if (msg) {</span><br><span style="color: hsl(0, 100%, 40%);">- stasis_publish(ast_channel_topic(chan), msg);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp_appl = ast_channel_appl(chan) ? ast_strdupa(ast_channel_appl(chan)) : NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp_data = ast_channel_data(chan) ? ast_strdupa(ast_channel_data(chan)) : NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_appl_set(chan, app);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_data_set(chan, !ast_strlen_zero(appdata) ? appdata : "(NULL)");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_publish_snapshot(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_appl_set(chan, tmp_appl);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_data_set(chan, tmp_data);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span> }</span><br><span> res = pbx_exec(chan, a, appdata);</span><br><span> } else</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15232">change 15232</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/+/15232"/><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: I9a2cfa0ec285169317f4b9146e4027da8a4fe896 </div>
<div style="display:none"> Gerrit-Change-Number: 15232 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Kevin Harwell <kharwell@digium.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: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>