From b1e960cfae6352f271bda14d50b7ed4b3ea57d80 Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 29 Oct 2019 22:48:14 +0100 Subject: [PATCH] omemo: Check stanza names when iterating nodes Some clients (eg. PSI) are sending the stanzas delimited by whitespace text nodes, which will fail while looping through the children and also print weird errors when iterating through the of devices. When debugging this, I was looking at the XML of Gajim and PSI and first was somehow confused why Profanity printed "OMEMO: received device without ID" while the XML looked identical (minus the actual IDs and the JIDs of course). However, Gajim was sending the XML without whitespace nodes in between and PSI did not, so for example the following (with the relevant whitespace nodes marked with X): X X X ... would result in three times the "OMEMO: received device without ID" error, because we actually have three XML text nodes here that obviously don't have an "id" attribute. Now since the children above aren't really a problem and only annoying, text nodes in the stanza actually cause omemo_start_device_session_handle_bundle to return failure. I've fixed this by explicitly matching the stanza names we are interested in, skipping everything else. Signed-off-by: aszlig Reported-by: @devhell --- src/xmpp/omemo.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/xmpp/omemo.c b/src/xmpp/omemo.c index 79d74ffb..e3c79722 100644 --- a/src/xmpp/omemo.c +++ b/src/xmpp/omemo.c @@ -164,6 +164,10 @@ omemo_start_device_session_handle_bundle(xmpp_stanza_t *const stanza, void *cons xmpp_stanza_t *prekey; for (prekey = xmpp_stanza_get_children(prekeys); prekey != NULL; prekey = xmpp_stanza_get_next(prekey)) { + if (g_strcmp0(xmpp_stanza_get_name(prekey), "preKeyPublic") != 0) { + continue; + } + omemo_key_t *key = malloc(sizeof(omemo_key_t)); key->data = NULL; @@ -378,6 +382,10 @@ _omemo_receive_devicelist(xmpp_stanza_t *const stanza, void *const userdata) xmpp_stanza_t *device; for (device = xmpp_stanza_get_children(list); device != NULL; device = xmpp_stanza_get_next(device)) { + if (g_strcmp0(xmpp_stanza_get_name(device), "device") != 0) { + continue; + } + const char *id = xmpp_stanza_get_id(device); if (id != NULL) { device_list = g_list_append(device_list, GINT_TO_POINTER(strtoul(id, NULL, 10)));