about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2019-10-29 22:48:14 +0100
committeraszlig <aszlig@nix.build>2019-10-29 23:10:07 +0100
commitb1e960cfae6352f271bda14d50b7ed4b3ea57d80 (patch)
tree85eb7414470921fa517e90d234f8bccd1c967e0f /src/xmpp
parent900426025e49224875709faccd619d7fd5944496 (diff)
downloadprofani-tty-b1e960cfae6352f271bda14d50b7ed4b3ea57d80.tar.gz
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 <prekeys/>
children and also print weird errors when iterating through the <list/>
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):

  <message type="headline" to="..." from="...">
    <event xmlns="http://jabber.org/protocol/pubsub#event">
      <items type="headline" node="eu.siacs.conversations.axolotl.devicelist">
        <item id="...">
          <list xmlns="eu.siacs.conversations.axolotl">
          X <device id="..."/>
          X <device id="..."/> X
          </list>
        </item>
      </items>
    </event>
    <delay xmlns="urn:xmpp:delay" stamp="..." from="..."/>
  </message>

... 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 <list/> children above aren't really a problem and only
annoying, text nodes in the <prekeys/> 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 <aszlig@nix.build>
Reported-by: @devhell
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/omemo.c8
1 files changed, 8 insertions, 0 deletions
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)));