Skip to content

Commit

Permalink
Merge pull request #1869 from profanity-im/fix/1868-mam
Browse files Browse the repository at this point in the history
Fix crash if we don't get `first` stanza during RSM
  • Loading branch information
jubalh authored Jul 18, 2023
2 parents 4814887 + a963ff4 commit 69d8c1f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
10 changes: 10 additions & 0 deletions profanity.doap
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@
</xmpp:SupportedXep>
</implements>

<!-- XEP-0059: Result Set Management -->
<implements>
<xmpp:SupportedXep>
<xmpp:xep rdf:resource='https://xmpp.org/extensions/xep-0059.html'/>
<xmpp:status>complete</xmpp:status>
<xmpp:version>1.0</xmpp:version>
<xmpp:since>DEV</xmpp:since>
</xmpp:SupportedXep>
</implements>

<!-- XEP-0060: Publish-Subscribe -->
<implements>
<xmpp:SupportedXep>
Expand Down
42 changes: 22 additions & 20 deletions src/xmpp/iq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2738,29 +2738,31 @@ _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata)

auto_char char* firstid = NULL;
xmpp_stanza_t* first = xmpp_stanza_get_child_by_name(set, STANZA_NAME_FIRST);
firstid = xmpp_stanza_get_text(first);
if (first) {
firstid = xmpp_stanza_get_text(first);

// 4.3.2. send same stanza with set,max stanza
xmpp_ctx_t* const ctx = connection_get_ctx();
// 4.3.2. send same stanza with set,max stanza
xmpp_ctx_t* const ctx = connection_get_ctx();

if (data->end_datestr) {
free(data->end_datestr);
data->end_datestr = NULL;
if (data->end_datestr) {
free(data->end_datestr);
data->end_datestr = NULL;
}
xmpp_stanza_t* iq = stanza_create_mam_iq(ctx, data->barejid, data->start_datestr, NULL, firstid, NULL);

MamRsmUserdata* ndata = malloc(sizeof(*ndata));
*ndata = *data;
if (data->end_datestr)
ndata->end_datestr = strdup(data->end_datestr);
if (data->start_datestr)
ndata->start_datestr = strdup(data->start_datestr);
if (data->barejid)
ndata->barejid = strdup(data->barejid);
iq_id_handler_add(xmpp_stanza_get_id(iq), _mam_rsm_id_handler, (ProfIqFreeCallback)_mam_userdata_free, ndata);

iq_send_stanza(iq);
xmpp_stanza_release(iq);
}
xmpp_stanza_t* iq = stanza_create_mam_iq(ctx, data->barejid, data->start_datestr, NULL, firstid, NULL);

MamRsmUserdata* ndata = malloc(sizeof(*ndata));
*ndata = *data;
if (data->end_datestr)
ndata->end_datestr = strdup(data->end_datestr);
if (data->start_datestr)
ndata->start_datestr = strdup(data->start_datestr);
if (data->barejid)
ndata->barejid = strdup(data->barejid);
iq_id_handler_add(xmpp_stanza_get_id(iq), _mam_rsm_id_handler, (ProfIqFreeCallback)_mam_userdata_free, ndata);

iq_send_stanza(iq);
xmpp_stanza_release(iq);
}
}
}
Expand Down

0 comments on commit 69d8c1f

Please sign in to comment.