1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00

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
This commit is contained in:
Michael Vetter 2022-01-27 11:52:23 +01:00
parent fada16bd6d
commit b1929068ff

View File

@ -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) {