about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2021-03-25 11:43:42 +0100
committerMichael Vetter <jubalh@iodoru.org>2021-03-25 11:43:42 +0100
commit96b228728e565422d6395efbfb87c22da68550e0 (patch)
treed03d93153982d7f553d9bbcd80ac777687cd0992
parentf21a99eaf8fcad5456110580b5aed1264f25060b (diff)
downloadprofani-tty-96b228728e565422d6395efbfb87c22da68550e0.tar.gz
message: fix possible segfault in _handle_conference
-rw-r--r--src/xmpp/message.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index 6924b509..3254f568 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -931,29 +931,33 @@ _handle_conference(xmpp_stanza_t* const stanza)
 {
     xmpp_stanza_t* xns_conference = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE);
 
-    const char* from = xmpp_stanza_get_from(stanza);
-    if (!from) {
-        log_warning("Message received with no from attribute, ignoring");
-        return;
-    }
+    if (xns_conference) {
 
-    Jid* jidp = jid_create(from);
-    if (!jidp) {
-        return;
-    }
+        const char* from = xmpp_stanza_get_from(stanza);
+        if (!from) {
+            log_warning("Message received with no from attribute, ignoring");
+            return;
+        }
 
-    // XEP-0249
-    const char* room = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_JID);
-    if (!room) {
-        jid_destroy(jidp);
-        return;
-    }
+        Jid* jidp = jid_create(from);
+        if (!jidp) {
+            return;
+        }
 
-    const char* reason = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_REASON);
-    const char* password = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_PASSWORD);
+        // XEP-0249
+        const char* room = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_JID);
+        if (!room) {
+            jid_destroy(jidp);
+            return;
+        }
 
-    sv_ev_room_invite(INVITE_DIRECT, jidp->barejid, room, reason, password);
-    jid_destroy(jidp);
+        // reason and password are both optional
+        const char* reason = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_REASON);
+        const char* password = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_PASSWORD);
+
+        sv_ev_room_invite(INVITE_DIRECT, jidp->barejid, room, reason, password);
+        jid_destroy(jidp);
+    }
 }
 
 static void