From b1929068ff581b3474f098866baf32ef851d8c18 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 27 Jan 2022 11:52:23 +0100 Subject: [PATCH] presence: guard against invalid input It shouldn't happen that we get the presence stanza without a resource. https://datatracker.ietf.org/doc/html/rfc6120 ``` Implementation Note: It is the server's responsibility to deliver only stanzas that are addressed to the client's full JID or the user's bare JID; thus, there is no need for the client to check the 'to' address of incoming stanzas. However, if the client does check the 'to' address then it is suggested to check at most the bare JID portion (not the full JID), since the 'to' address might be the user's bare JID, the client's current full JID, or even a full JID with a different resourcepart (e.g., in the case of so- called "offline messages" as described in [XEP-0160]). ``` Let's not segfault though. Close https://github.com/profanity-im/profanity/issues/1630 --- src/xmpp/presence.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index a9b07daa..b5cb1803 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -747,15 +747,19 @@ _muc_user_self_handler(xmpp_stanza_t* stanza) g_slist_free_full(status_codes, free); } } else { - gboolean config_required = stanza_muc_requires_config(stanza); - const char* actor = stanza_get_actor(stanza); - char* reason = stanza_get_reason(stanza); char* nick = from_jid->resourcepart; + if (!nick) { + log_warning("presence: jid without resource"); + return; + } + char* reason = stanza_get_reason(stanza); char* show_str = stanza_get_show(stanza, "online"); char* status_str = stanza_get_status(stanza, NULL); + const char* actor = stanza_get_actor(stanza); const char* jid = NULL; const char* role = NULL; const char* affiliation = NULL; + gboolean config_required = stanza_muc_requires_config(stanza); xmpp_stanza_t* x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); if (x) { xmpp_stanza_t* item = xmpp_stanza_get_child_by_name(x, STANZA_NAME_ITEM); @@ -786,6 +790,11 @@ _muc_user_occupant_handler(xmpp_stanza_t* stanza) char* nick = from_jid->resourcepart; char* status_str = stanza_get_status(stanza, NULL); + if (!nick) { + log_warning("presence: jid without resource"); + return; + } + const char* type = xmpp_stanza_get_type(stanza); if (g_strcmp0(type, STANZA_TYPE_UNAVAILABLE) == 0) {