about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorPaul Fariello <paul@fariello.eu>2019-06-21 12:34:19 +0200
committerPaul Fariello <paul@fariello.eu>2019-06-21 11:34:36 +0200
commita444137e66d9dc041c30b411d5904fb0075b3bea (patch)
tree49f9f84943d9d761068a3044ffd7f8fbbced615d
parentdb86286ea3f786b6eaecc7a7986335db563c1a9a (diff)
downloadprofani-tty-a444137e66d9dc041c30b411d5904fb0075b3bea.tar.gz
Fix NULL pointer when handling non encrypted message in MUC
-rw-r--r--src/xmpp/message.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index c100684e..3d4807fe 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -800,6 +800,8 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
     message->jid = jid;
     message->id = strdup(id);
 
+    message->body = xmpp_message_get_body(stanza);
+
     // check omemo encryption
 #ifdef HAVE_OMEMO
     message->plain = omemo_receive_message(stanza, &message->trusted);
@@ -808,7 +810,12 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
     }
 #endif
 
-    message->body = xmpp_message_get_body(stanza);
+    if (!message->plain && !message->body) {
+        log_error("Message received without body for room: %s", jid->str);
+        goto out;
+    } else if (!message->plain) {
+        message->plain = strdup(message->body);
+    }
 
     // determine if the notifications happened whilst offline
     message->timestamp = stanza_get_delay(stanza);
@@ -818,6 +825,7 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
         sv_ev_room_message(message);
     }
 
+out:
     message_free(message);
 }