]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_xmpp: Don't crash when trying to send a message without a connection
authorSean Bright <sean.bright@gmail.com>
Wed, 22 Mar 2017 22:32:37 +0000 (18:32 -0400)
committerSean Bright <sean.bright@gmail.com>
Thu, 23 Mar 2017 14:57:02 +0000 (08:57 -0600)
If we never establish a connection to our Jabber server, iksemel never sets up
its internal transport pointer, so attempting to send a message dereferences a
NULL pointer and causes a crash.

ASTERISK-21855 #close
Reported by: Jeremy Kister

Change-Id: I204a568894e4a53ab929783ecc594a000f04d79c

res/res_xmpp.c

index 32e1dd1ffc9fa804f6c36585995350709118c9db..6675ad475190a8cc2909e00720afb032848a9a30 100644 (file)
@@ -2564,10 +2564,16 @@ static void xmpp_log_hook(void *data, const char *xmpp, size_t size, int incomin
 static int xmpp_client_send_raw_message(struct ast_xmpp_client *client, const char *message)
 {
        int ret;
-#ifdef HAVE_OPENSSL
-       int len = strlen(message);
 
+       if (client->state == XMPP_STATE_DISCONNECTED) {
+               /* iks_send_raw will crash without a connection */
+               return IKS_NET_NOCONN;
+       }
+
+#ifdef HAVE_OPENSSL
        if (xmpp_is_secure(client)) {
+               int len = strlen(message);
+
                ret = SSL_write(client->ssl_session, message, len);
                if (ret) {
                        /* Log the message here, because iksemel's logHook is